Solved

Keep button enabled on page return

Posted on 2004-10-20
12
192 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 50

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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

Author Comment

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

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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

810 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