Steps for concealing the subsequent button in a Qualtrics survey until a specific time of day

I've been attempting to conceal the next button on a Qualtrics survey until a specific day and time (stored as 'threshold' in my code). I've experimented with

Qualtrics.SurveyEngine.addOnload(function()
{
    var threshold = '2020-02-07T20:00:00.000Z';
    var today = new Date();
    if(threshold < today) $('NextButton').hide();
    else $('NextButton').show();

});

along with

Qualtrics.SurveyEngine.addOnload(function() {   
    function hideEl(element) {
        element.hide();
    }   
    var nb = $('NextButton');
    var threshold = '2020-02-07 08:12';
    var today = new Date();
    var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
    var time = today.getHours() + ":" + today.getMinutes();
    var dateTime = date+' '+time;
        hideEl.defer(nb);
    if(var dateTime < threshold ) nb.hide();
    else nb.show();

    });

and

Qualtrics.SurveyEngine.addOnload(function() {
    function hideEl(element) {
        element.hide();
    }
    var threshold = '2020-02-07T20:00:00.000Z';
    var today = new Date();
    var nb = $('NextButton');
    hideEl.defer(nb);
 $(this.questionId).on('display', function(event) {
        if(today<threshold) nb.hide();
        else nb.show();
    });
});

Unfortunately, none of these attempts have successfully achieved the desired result. Any suggestions?

Thank you!!

Answer №1

If you are eager to see the page load with your button visible, simply waiting in place will not suffice. This is because your onload code only executes once. To resolve this issue, one solution is to determine the amount of time (in milliseconds) it will take for your button to appear after the page loads. Subsequently, you can set a timeout function to trigger the display of the button once that specified duration has elapsed.

function onLoadCb() {
  // Specify when you want your button to become visible:
  const timeToShow = new Date('<enter your desired date>');
  // Convert the specified time to milliseconds:
  const msToShow = Number(timeToShow);
  // Obtain the current time in milliseconds:
  const now = Date.now();
  // Perform necessary calculations:
  const msToWait = msToShow - now;

  // Implement a timeout function to trigger the button display after the calculated delay:
  setTimeout(() => {
    // It's time to reveal the button!
    $('.NextButton').show();
  }, msToWait);
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is your Node.js HTTP Request failing to function properly?

I am currently working on creating an HTTP Request function where all requests are directed to the same domain but with different file names. Unfortunately, I am encountering a problem where nothing is being displayed in the console and no data is being r ...

Firebase authentication encountered an error due to a network request failure

Utilizing firebase Hosting to host my website, I am encountering a persistent error when attempting to login using email/password. This is the JavaScript code that I am using: window.onload = () => initApp(); //Initialize screen function initApp(){ ...

Latest output is fetched by jQuery from the load() method

I'm encountering an issue with the code present in index.html: $(document).ready(function() { $('#generate').click(function() { //$("#results").empty(); $("#results").html(""); $("#results").load("generate.php"); }); }); In addition ...

Function asynchronously returning Promise even after Await statement is executed

I've been attempting to develop a function that retrieves data from a document in the Firebase database using Nodejs: module.exports = async (collectionName, documentId, res) => { const collection = db.doc(`/${collectionName}/${documentId}`); t ...

Vue automatically clears the INPUT field when disabling it

Have you ever noticed why Vue resets a text input field when it's set to disabled? This behavior is not observed with plain Javascript and also doesn't affect textarea fields. var app = new Vue({ el: '.container', data: { disab ...

React 18 doesn't trigger component re-rendering with redux

In my code, I have implemented a custom hook to handle global data fetching based on user authentication. Here is an example of the hook: const userState = useSelector(state => state.user.state) useEffect(() => { if(userState === "authentic ...

Expo project encountering issues with nested navigation in React-Native

When configuring the header in my app using React Native Stack Navigation and nesting a Drawer Navigation inside of it, I encountered a strange issue. While everything worked fine in the android emulator, opening the app using Expo resulted in nothing but ...

utilizing staggered animations with three.js

I am trying to animate an array of meshes in Three.js, but the properties are not being recognized. tl.staggerFrom(array, 2, {"position.y":-100}) The position.y doesn't change. When I use console.log(array[0].position.y), it gives me the initial val ...

Error: Variable 'err' is undefined in Node.js

Why am I getting a ReferenceError: err is not defined even though it is supposed to be defined here? const sampleObject = require('./sampleObject'); const sampleModel = (callback) => { if (true) { sampleObject.sampleRetrieval(err ...

Tips for adding a new property to an array object in TypeScript using a condition

Here is an array object that I have: arr = [ { Name: "ABC", Age: 20}, { Name: "XXX", Age: 15} ]; In Typescript, I am looking to dynamically add a new property called "Flag" with a value of 1 only if the Age is greater than 15. Can someone suggest ...

React Native - A button positioned with a lower zIndex will always be displayed on top of a view with a higher

I am facing an interesting scenario where a button with zIndex: 5 is positioned on top of an Interactable.View with zIndex: 19. EDIT: Although the button appears to be on top, it is visible but not responsive (lack of tap functionality). Below is the cod ...

Issues with Autofocus while Searching and Selecting from Dropdown menu

Here is the JavaScript code I am using: <script type="text/javascript"> function handleSelectionChange(selectElement, nextField) { nextField.focus(); } function handleKeyPress(event, currentField, nextField) { i ...

Utilize mongoose-delete to bring back items that have been marked for deletion but are still

Whenever I remove an item from my list, it switches the properties of the data to true, marking it as deleted and moves it to the trash. However, when I try to restore the item from the trash, the deleted properties are no longer available and the data rea ...

Attempting to persist a nested document in MongoDB using mongoose within a Nodejs environment

I attempted to save an address as a nested document in the following format When sending data from the client side, it was formatted like this: const address = JSON.stringify( { addressline1:form.addressline1.value, addressline2:form.addressline2.value, c ...

Accessing Next and Previous Elements Dynamically in TypeScript from a Dictionary or Array

I am new to Angular and currently working on an Angular 5 application. I have a task that involves retrieving the next or previous item from a dictionary (model) for navigation purposes. After researching several articles, I have devised the following solu ...

Guide on how to use JavaScript to make an HTML5 input field mandatory

I am facing an issue with setting input fields as required based on radio button selection in a form. Initially, all fields should have required=false, but I'm unable to achieve this. No matter what value I assign to the required attribute, it always ...

YUI3 Searching with Selectors

I'm encountering an issue with selecting a single checkbox object in YUI3 based on its unique value attribute. In a table, there are multiple checkboxes with assigned unique keys to their value attributes. What should be the correct selector in YUI3 t ...

What is the best way to incorporate a state variable into a GraphQL query using Apollo?

My current challenge involves using a state as a variable for my query in order to fetch data from graphQl. However, I'm encountering an issue where the component does not read the state correctly. Any suggestions on how to solve this? class usersSc ...

Disable the scroll bar on a bootstrap modal

<span class="education"style="font-size:170%;line-height:150%;">&nbsp;Education <br> <small style=" color:gray;font-size:60%;">&nbsp; Blue Ridge University,2012-2014 </small> <br> <sma ...

How can I make an image appear in React when it is

I am currently looking to incorporate an image every time I click incrementally. I attempted the solution below, which is in the commented-out section. BallonTest = () => { const [money, setMoney] = useState(0); const [bank, setBank] = useState(0); ...