Search the Legacy Support Archive (up to v2020)
  1. Read-only archive (2005–2024). Posting is closed. Need help with MediaLab or DirectRT 2027? Email service@empirisoft.com.

    All words · “exact phrase” · -leave out

    Advanced search

javascript alert box in custom html item

  1. #1

    javascript alert box in custom html item

    I have a custom item html form that I need to automatically submit after a given duration. I've successfully written a javascript that submits the form based on the duration time specified in the medialab duration variable, but I also want to alert the user that their time is up before the submission occurs so that the item doesn't seem to randomly change.

    The code for the alert box and submit function works fine by itself, but when I run it through ML, only the submit timer works, the alert box is nowhere to be seen.

    Here is my code:

    <script>
    function alert_and_submit()
    {
    alert("Out of time. Please hit OK");
    document.creativityform.submit()
    }
    setTimeout("alert_and_submit()", <ml.d>000);

    </script>

  2. #2
    Cancel that. The problem is that ML is incorrectly using the "d" variable to skip the html page after the specified time, rather than passing it to the <ml.d> placeholder in the html file.

    This doesn't make much sense. Putting up a custom html item, and skipping without submitting the form, is pretty useless. Am I missing something?

  3. #3
    Anyone?.....

  4. #4
    hi jzadra,

    we exclusively use custom items and use javascript to time the appearance of the button as well as the presentation of text and so on.

    show button:
    function showButton(){
    var timeOut = 50000;
    setTimeout(&#x27;document.getElementById(&quot;button&quot;).style.display = &quot;block&quot;&#x27;, timeOut);
    };


    timed presentation:
    &lt;body onload=&quot;window.setTimeout(advance, 5000, true);&quot;&gt;
    &lt;!-- this content is presented right away --&gt;
    &lt;div id=&quot;first&quot;&gt;&lt;p&gt;Some kind of instruction&lt;/p&gt;&lt;/div&gt;

    &lt;!-- this content is presented after 5 seconds --&gt;
    &lt;div id=&quot;second&quot;&gt;&lt;p&gt;Some kind of instruction&lt;/p&gt;&lt;/div&gt;

    &lt;!-- On pages containing only instructions we use this command to send an empty variable to ML so that it proceeds to the next page. --&gt;
    &lt;form method=&quot;post&quot;&gt;
    &lt;input type=&quot;hidden&quot; name=&quot;whatever&quot;/&gt;
    &lt;input type=&quot;submit&quot; value=&quot;submit&quot;/&gt;
    &lt;/form&gt;


    I am not sure if this is what you are looking for but perhaps it'll do:)

    Best
    Rene