Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7308661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T23:35:17+00:00 2026-05-28T23:35:17+00:00

I am new to java-script and have made this script to popup this custom

  • 0

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.

<head>
<style type="text/css">
.alertbox{
position:absolute;
top:0;
left:0;
width:100%;
height:100%;
background-color:rgba(0,0,0,.6);
z-index:100;
display:none;
}
</style>

<script type="text/javascript">

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;} 
}

</script>
</head>

<body>
<input type="button" value="Send" onclick="eSubmit()">

<div id="msgSend" class="alertbox">
    <div onClick="txtChange()">
        <p id="thanks">Thank you for submitting your e-mail.</P>
    </div>
</div>

</body>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T23:35:18+00:00Added an answer on May 28, 2026 at 11:35 pm

    Just guessing, but look into this

       if(msgBox.style.display == 'block' || msgBox.style.display ==''){
          msgBox.style.display = 'none';}
    

    The display property is set to an empty string even if there’s an explicit setting inside . According to the W3C recommendation, .style-properties are only reflecting properties set inside the style=””-attribute of the element itself, not any computed or inherited settings defined elsewhere.

    Because of that the if-statement becomes true and sets display to none on the first click.

    Solution: change your if-else-logic or initialize the CSS display property as a style-attribute matching your needs

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made a custom block in Magento that contains some JS. I want
I made this PHP chatbox which supports some JavaScript code. I have these 'images'
I have used Javascript onlaod like this: function check() { var pic = new
I have some code that dynamically creates a new button through JavaScript that when
I want it to have a popup dialog javascript box. Instead of a new
I have a table in HTML. I have made this table as editable by
I'm using php,html,javascript,mysql. My functionality goes like this. I have a division made in
I work with many small, but unrelated java projects. I made an Ant script
I know there are some questions touching this subject, but none have helped me
I have run the following code in this page RsyntaxTextArea using Java and i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.