• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 201
  • Last Modified:

Keep button enabled on page return

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
blnukem
Asked:
blnukem
  • 5
  • 3
  • 2
  • +1
1 Solution
 
RoonaanCommented:
<body onload="enableButton();">

Regards

-r-
0
 
Ryan ChongCommented:
and make sure you add a checked there by default:

<input type="checkbox" id="SiteTerms" name="SiteTerms" value="Yes" onClick="enableButton();" checked>
0
 
RoonaanCommented:
@ryancys:

It shouldn't be checked by default should it?

regards

-r-
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
blnukemAuthor Commented:
yes it should be unchecked by default.
0
 
Ryan ChongCommented:
k, my mistake! ..
0
 
thirdCommented:
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
 
thirdCommented:
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
 
thirdCommented:
btw, disregard the form action on my first example. i used it for testing purposes only.
0
 
blnukemAuthor Commented:
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
 
thirdCommented:
include,

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

or

<body onload="document.getElementById('SiteTerms').checked=false;">
0
 
thirdCommented:
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
 
blnukemAuthor Commented:
OK that will work!
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 5
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now