Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does my Submit button require 2 clicks before running desired script the first time?
    primarykey
    data
    text
    <p>I am new to java-script and have made this script to popup this custom message when a visitor submits an e-mail. However, for some reason the 'display:block' only happens after the second time the user clicks "Submit" and not after the first click. However, each subsequent time after that (unless the page is reloaded) the function works with only 1 click. The only way I have been able to make it function as desired is by adding onLoad="eSubmit" to hte body tag (essentially taking the place of the first click), but I don't want to have to do that. All applicable code I have is below... I would appreciate any help, thanks.</p> <pre><code>&lt;head&gt; &lt;style type="text/css"&gt; .alertbox{ position:absolute; top:0; left:0; width:100%; height:100%; background-color:rgba(0,0,0,.6); z-index:100; display:none; } &lt;/style&gt; &lt;script type="text/javascript"&gt; function eSubmit() { var msgBox = document.getElementById("msgSend"); var responseTxt = document.getElementById("thanks"); if(msgBox.style.display == 'block' || msgBox.style.display ==''){ msgBox.style.display = 'none';} else{ msgBox.style.display = 'block';} if(responseTxt.innerHTML == 'Returning to page...'){ responseTxt.innerHTML = 'Thank you for submitting your e-mail.';} } function txtChange(){ var E = setTimeout("eSubmit()",1000); var responseTxt = document.getElementById("thanks"); if(responseTxt.innerHTML == 'Thank you for submitting your e-mail.'){ responseTxt.innerHTML = "Returning to page..."; E;} } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;input type="button" value="Send" onclick="eSubmit()"&gt; &lt;div id="msgSend" class="alertbox"&gt; &lt;div onClick="txtChange()"&gt; &lt;p id="thanks"&gt;Thank you for submitting your e-mail.&lt;/P&gt; &lt;/div&gt; &lt;/div&gt; &lt;/body&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload