943,915 Members | Top Members by Rank

Ad:
Aug 21st, 2009
0

Another Checkbox question!

Expand Post »
Hi folks,
I'm afraid I'm pretty new to javascript, so I apologize in advance for my inexperience. I am trying to do a simple thing:

I have a page with three items that I want the user to agree to (a beta signup agreement).

I want them to have to check off all three boxes before the "continue" button becomes active.

I've searched and searched and found a few tutorials, but they only seem to get me halfway and then drop me off a cliff...

I don't need this to be a submit form or anything, just click the three boxes and then you can hit the "continue" button.

Thank you for your help!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
mbirame is offline Offline
34 posts
since Apr 2009
Aug 21st, 2009
0

Re: Another Checkbox question!

First you have to disable the submit button then on each checkboxes onclick event do a check to see if all of them are checked, then enable the button again.

code will look something like this:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function check(){
  2. if (document.getElementById('chkId1').checked==true && document.getElementById('chkId2').checked==true && document.getElementById('chkId3').checked==true){
  3. document.getElementById(button).disabled = ' ';
  4. }
  5. }
Reputation Points: 36
Solved Threads: 57
Posting Whiz
Thirusha is offline Offline
355 posts
since Mar 2008
Aug 21st, 2009
0

Re: Another Checkbox question!

Would you be willing to give me a snip of html to see what the checkbox and button would look like there in reference to this code?

Thank you for your help!
Reputation Points: 10
Solved Threads: 0
Light Poster
mbirame is offline Offline
34 posts
since Apr 2009
Aug 21st, 2009
0

Re: Another Checkbox question!

I've got this much, but still trying to figure out the button...

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <script type="text/javascript">
  2. <!--
  3. function check(){
  4. if (document.getElementById('chkId1').checked==true && document.getElementById('chkId2').checked==true && document.getElementById('chkId3').checked==true){
  5. document.getElementById(button).disabled = ' ';
  6. }
  7. }
  8. // -->
  9. </script>
  10.  
  11.  
  12.  
  13.  
  14. <input name="chkId1" value="1" id="chkId1" type="checkbox">
  15. Terms Agreement</label>
  16. <br>
  17. <label for="myCheckbox2"><input name="chkId2" value="2" id="chkId2" type="checkbox">
  18. Unstable</label>
  19. <br>
  20. <label for="myCheckbox3"><input name="chkId3" value="3" id="chkId3" type="checkbox">
  21. Feedback</label>
Reputation Points: 10
Solved Threads: 0
Light Poster
mbirame is offline Offline
34 posts
since Apr 2009
Aug 21st, 2009
0

Re: Another Checkbox question!

Hi everyone,

mbirame — you could also try this one:
javascript Syntax (Toggle Plain Text)
  1. <?xml version="1.0" encoding="utf-8" standalone="no"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  3. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4. <html id="xhtml10" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  5. <!-- W3Cs Standard Template : XHTML 1.0 Transitional DTD -->
  6. <head>
  7. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  8. <meta http-equiv="Content-Script-Type" content="text/javascript" />
  9. <title>www.daniweb.com</title>
  10. <style type="text/css" media="all">
  11. /* <![CDATA[ */
  12.  
  13. /* ]]> */
  14. </style>
  15. <script type="text/javascript">
  16. // <![CDATA[
  17. var validate = function( form ) {
  18. var form = ( typeof( form ) === "object" ) ? form : document.getElementById( form );
  19. var pref = "chb";
  20. for ( var i = 0; i < 3; i++ ) {
  21. if ( form[( pref + i )].checked ) {
  22. continue;
  23. return true;
  24. } alert( "In order to continue, you must check all 3 items in the field" );
  25. return false;
  26. }
  27. };
  28. // ]]>
  29. </script>
  30. </head>
  31. <body id="body0">
  32. <div>
  33. <form id="testform" name="testform" action="process.php" onsubmit="return validate( this );">
  34. <div id="div0">
  35. <label for="chb0"><b>1.</b> Item <input type="checkbox" id="chb0" name="chb0" value="item1" /></label><br />
  36. <label for="chb1"><b>2.</b> Item <input type="checkbox" id="chb1" name="chb1" value="item1" /></label><br />
  37. <label for="chb2"><b>3.</b> Item <input type="checkbox" id="chb2" name="chb2" value="item3" /></label><br /><br />
  38. <input type="submit" value="continue" />
  39. </div>
  40. </form>
  41. </div>
  42. </body>
  43. </html>

hope it both helped...
Featured Poster
Reputation Points: 114
Solved Threads: 138
Posting Shark
essential is offline Offline
973 posts
since Aug 2008
Aug 21st, 2009
0

Re: Another Checkbox question!

Holy cow-that works beautifully! Thank you both! This was written in a way that I can learn too! Yea!
Reputation Points: 10
Solved Threads: 0
Light Poster
mbirame is offline Offline
34 posts
since Apr 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Date d-m-yy to dd-mm-yyyy
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: How to intregrate javascript code of selecting dropdownlist item from a asp.net form?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC