Solved

Keep button enabled on page return

Posted on 2004-10-20
12
186 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
  • 5
  • 3
  • 2
  • +1
12 Comments
 
LVL 49

Expert Comment

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

Regards

-r-
0
 
LVL 49

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
 

Author Comment

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

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now