Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Keep button enabled on page return

Posted on 2004-10-20
12
Medium Priority
?
199 Views
Last Modified: 2008-03-06
Hi all I using this script to enable a button but my problem is that if the user moves ahead to the next page and then hits return the check box is still check and the button is then disabled I would like to keep the button enabled if possible.

<script type="text/javascript">
  function enableButton(){
   if(document.getElementById('SiteTerms').checked){
        document.getElementById('Submit').disabled =false;
       }else{
        document.getElementById('Submit').disabled =true;
       }
  }
</script>

<form>
<input type="checkbox" id="SiteTerms" name="SiteTerms" value="Yes" onClick="enableButton();">
  I understand the terms and conditions.<br>
  <input type="submit" name="submit"value="Confirm ->"disabled>
</form>
0
Comment
Question by:blnukem
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
  • +1
12 Comments
 
LVL 49

Expert Comment

by:Roonaan
ID: 12356303
<body onload="enableButton();">

Regards

-r-
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 12356333
and make sure you add a checked there by default:

<input type="checkbox" id="SiteTerms" name="SiteTerms" value="Yes" onClick="enableButton();" checked>
0
 
LVL 49

Expert Comment

by:Roonaan
ID: 12356358
@ryancys:

It shouldn't be checked by default should it?

regards

-r-
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:blnukem
ID: 12356394
yes it should be unchecked by default.
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 12356413
k, my mistake! ..
0
 
LVL 30

Expert Comment

by:third
ID: 12356440
we can shorten the code with this,

<html>
<head>
</head>
<body onload="document.form1.SiteTerms.checked=false;">
<form name="form1" action="hover.html" method=post action="" onsubmit="">
<input type="checkbox" id="SiteTerms" name="SiteTerms" value="Yes" onClick="this.form.MySubmit.disabled=!this.checked">
  I understand the terms and conditions.<br>
  <input type="submit" name="MySubmit" value="Confirm ->"disabled>
</form>
</body>
</html>
0
 
LVL 30

Expert Comment

by:third
ID: 12356452
or if you still prefer your old method, you can just write it like this,

function enableButton(){
   document.getElementById('Submit').disabled = !document.getElementById('SiteTerms').checked;
}
0
 
LVL 30

Expert Comment

by:third
ID: 12356459
btw, disregard the form action on my first example. i used it for testing purposes only.
0
 

Author Comment

by:blnukem
ID: 12356552
OK here is what we have now BUT the button it is still disabled on return.

<script type="text/javascript">
function enableButton(){
   document.getElementById('Submit').disabled = !document.getElementById('SiteTerms').checked;
}
</script>

<form>

    <input type="checkbox" id="SiteTerms" name="SiteTerms" value="Yes" onClick="enableButton();">
    I understand the terms and conditions.<br>
    <input type="button" name="submit" value="Confirm ->" onClick="parent.location='http://www.google.com'" disabled>

</form>
0
 
LVL 30

Expert Comment

by:third
ID: 12356582
include,

<body onload="document.forms[0].SiteTerms.checked=false;">

or

<body onload="document.getElementById('SiteTerms').checked=false;">
0
 
LVL 30

Accepted Solution

by:
third earned 2000 total points
ID: 12356596
try this,

<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script>
function enableButton(){
   document.getElementById('Submit').disabled = !document.getElementById('SiteTerms').checked;
}
</script>
</head>
<body onload="document.forms[0].SiteTerms.checked=false;">
<form>
    <input type="checkbox" id="SiteTerms" name="SiteTerms" value="Yes" onClick="enableButton();">
    I understand the terms and conditions.<br>
    <input type="button" name="submit" value="Confirm ->" onClick="parent.location='http://www.google.com'" disabled>

</form>
</body>
</html>
0
 

Author Comment

by:blnukem
ID: 12356624
OK that will work!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question