Solved

Keep button enabled on page return

Posted on 2004-10-20
12
198 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 52

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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

Author Comment

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

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 500 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…
Suggested Courses

623 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