chechbox validations

Reply

Join Date: Sep 2009
Posts: 128
Reputation: muralikalpana is an unknown quantity at this point 
Solved Threads: 7
muralikalpana's Avatar
muralikalpana muralikalpana is offline Offline
Junior Poster

chechbox validations

 
0
  #1
Nov 6th, 2009
hello friends ..



i want to do one task. i want some one elp. i am new to php. when ever i check the checkbox amount will add in 'total' textbox.
i am displaying table below.
  1. <form name="form" action="" method="post" >
  2. <table align="center">
  3. <tr>
  4. <td>&nbsp;</td>
  5. </tr>
  6. <tr>
  7. <td>&nbsp;</td>
  8. </tr>
  9. <tr>
  10. <td>&nbsp;</td>
  11. </tr>
  12. <tr>
  13. <td>
  14. Make my add featured $19.95 (your ad seen before free listings)
  15. </td>
  16. <td>&nbsp;</td>
  17. <td><input type="checkbox" name="chk1" onclick="check1()"/></td></tr>
  18.  
  19. <tr>
  20. <td>&nbsp;</td>
  21. <td>&nbsp;</td>
  22. </tr>
  23. <tr>
  24. <td>
  25. Make my ad bold $4.95
  26. </td>
  27. <td>&nbsp;</td>
  28. <td><input type="checkbox" name="chk2" /></td></tr>
  29. <tr>
  30. <td>&nbsp;</td>
  31. <td>&nbsp;</td>
  32. </tr>
  33. <tr>
  34. <td>
  35. Make my ad highlighted $4.95
  36. </td>
  37. <td>&nbsp;</td>
  38. <td><input type="checkbox" name="chk3" /></td></tr>
  39. <tr>
  40. <td>&nbsp;</td>
  41. <td>&nbsp;</td>
  42. </tr>
  43. <tr>
  44. <td>
  45. Add Email $9.95
  46. </td>
  47. <td><input type="text" name="email" /></td>
  48. <td><input type="checkbox" name="chk4" /></td></tr>
  49. <tr>
  50. <td>&nbsp;</td>
  51. <td>&nbsp;</td>
  52. </tr>
  53. <tr>
  54. <td>
  55. Add link to my website $9.95
  56. </td>
  57. <td><input type="text" name="link" /></td>
  58. <td><input type="checkbox" name="chk5" /></td>
  59. </tr>
  60. <tr>
  61. <td>&nbsp;</td>
  62. <td>&nbsp;</td>
  63. </tr>
  64. <tr>
  65. <td>Add 10 key words $9.95&nbsp;&nbsp;&nbsp;<input type="checkbox" name="chk6" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  66. or</td>
  67. <td>Add 20 keywords $19.95&nbsp;&nbsp;&nbsp;<input type="checkbox" name="chk7" /></td>
  68. </tr>
  69. <tr>
  70. <td><textarea name="text1" rows="6" cols="50"></textarea></td>
  71. <td>&nbsp;</td>
  72. </tr>
  73. <tr>
  74. <td>&nbsp;</td>
  75. <td>&nbsp;</td>
  76. </tr>
  77. <tr>
  78. <td>
  79. Add larger description (up to 4,000 charters) $29.95
  80. </td>
  81. <td>&nbsp;</td>
  82. <td><input type="checkbox" name="chk8" /></td></tr>
  83. <tr>
  84. <td>&nbsp;</td>
  85. <td>&nbsp;</td>
  86. </tr>
  87. <tr>
  88. <td><textarea name="text1" rows="6" cols="50"></textarea></td>
  89. <td>&nbsp;</td>
  90. </tr>
  91. <tr>
  92. <td>&nbsp;</td>
  93. <td>&nbsp;</td>
  94. </tr>
  95. <tr>
  96. <td>Add 10 key words $9.95&nbsp;&nbsp;&nbsp;<input type="checkbox" name="chk6" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  97. or</td>
  98. <td>Add 20 keywords $19.95&nbsp;&nbsp;&nbsp;<input type="checkbox" name="chk7" /></td>
  99. </tr>
  100. <tr>
  101. <td><textarea name="text1" rows="6" cols="50"></textarea></td>
  102. <td>&nbsp;</td>
  103. </tr>
  104. <tr>
  105. <td>&nbsp;</td>
  106. <td>&nbsp;</td>
  107. </tr>
  108. <tr>
  109. <td align="right">total &nbsp;&nbsp;&nbsp;<input name="total" type="text" /></td>
  110. </tr>
  111. </table>
  112. </form>

here no.of checkboxs. when ever i check one checkbox that amt willadd to total amount.
plz help me.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 883
Reputation: pritaeas will become famous soon enough pritaeas will become famous soon enough 
Solved Threads: 142
Sponsor
pritaeas's Avatar
pritaeas pritaeas is offline Offline
Practically a Posting Shark
 
0
  #2
Nov 6th, 2009
Found this link, and made it into this:
http://expressionengine.com/forums/viewthread/128806/

  1. <html>
  2. <head>
  3. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
  4. <script type="text/javascript">
  5. $(document).ready(function() {
  6. var total = 0;
  7.  
  8. function calcTotal()
  9. {
  10. $("input:checked").each(function()
  11. {
  12. var value = $(this).attr("value");
  13. total += parseFloat(value);
  14. });
  15. }
  16.  
  17. calcTotal();
  18.  
  19. $("input:checkbox, input:radio").click(function()
  20. {
  21. total = 0;
  22. calcTotal();
  23. $("input#total").val(total);
  24. });
  25. });
  26. </script>
  27. </head>
  28. <body>
  29. <form name="form" action="" method="post" >
  30. <table align="center">
  31. <tr>
  32. <td>Make my add featured $19.95 (your ad seen before free listings)</td>
  33. <td>&nbsp;</td>
  34. <td><input type="checkbox" value="19.95" /></td>
  35. </tr>
  36. <tr>
  37. <td>Make my ad bold $4.95</td>
  38. <td>&nbsp;</td>
  39. <td><input type="checkbox" value="4.95" /></td>
  40. </tr>
  41. <tr>
  42. <td>Make my ad highlighted $4.95</td>
  43. <td>&nbsp;</td>
  44. <td><input type="checkbox" value="4.95" /></td>
  45. </tr>
  46. <tr>
  47. <td>Add Email $9.95</td>
  48. <td><input type="text" name="email" /></td>
  49. <td><input type="checkbox" value="9.95" /></td>
  50. </tr>
  51. <tr>
  52. <td>Add link to my website $9.95</td>
  53. <td><input type="text" name="link" /></td>
  54. <td><input type="checkbox" value="9.95" /></td>
  55. </tr>
  56. <tr>
  57. <td>Add 10 key words $9.95 <input type="checkbox" value="9.95" /></td>
  58. <td>or</td>
  59. <td>Add 20 keywords $19.95 <input type="checkbox" value="19.95" /></td>
  60. </tr>
  61. <tr>
  62. <td><textarea name="text1" rows="6" cols="50"></textarea></td>
  63. <td>&nbsp;</td>
  64. <td>&nbsp;</td>
  65. </tr>
  66. <tr>
  67. <td>Add larger description (up to 4,000 charters) $29.95</td>
  68. <td>&nbsp;</td>
  69. <td><input type="checkbox" value="29.95" /></td>
  70. </tr>
  71. <tr>
  72. <td><textarea name="text1" rows="6" cols="50"></textarea></td>
  73. <td>&nbsp;</td>
  74. <td>&nbsp;</td>
  75. </tr>
  76. <tr>
  77. <td>Add 10 key words $9.95 <input type="checkbox" value="9.95" /></td>
  78. <td>or</td>
  79. <td>Add 20 keywords $19.95 <input type="checkbox" value="19.95" /></td>
  80. </tr>
  81. <tr>
  82. <td><textarea name="text1" rows="6" cols="50"></textarea></td>
  83. <td>&nbsp;</td>
  84. <td>&nbsp;</td>
  85. </tr>
  86. <tr>
  87. <td>&nbsp;</td>
  88. <td>&nbsp;</td>
  89. <td align="right">total <input id="total" type="text" /></td>
  90. </tr>
  91. </table>
  92. </form>
  93. </body>
  94. </html>
Last edited by pritaeas; Nov 6th, 2009 at 4:35 am. Reason: removed indent
"If it is NOT source, it is NOT software."
-- NASA
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 128
Reputation: muralikalpana is an unknown quantity at this point 
Solved Threads: 7
muralikalpana's Avatar
muralikalpana muralikalpana is offline Offline
Junior Poster
 
0
  #3
Nov 6th, 2009
how to call this function from form
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 883
Reputation: pritaeas will become famous soon enough pritaeas will become famous soon enough 
Solved Threads: 142
Sponsor
pritaeas's Avatar
pritaeas pritaeas is offline Offline
Practically a Posting Shark
 
0
  #4
Nov 6th, 2009
Originally Posted by muralikalpana View Post
how to call this function from form
Copy/paste this html into test.html, open it and see what happens when you click a checkbox...
"If it is NOT source, it is NOT software."
-- NASA
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 128
Reputation: muralikalpana is an unknown quantity at this point 
Solved Threads: 7
muralikalpana's Avatar
muralikalpana muralikalpana is offline Offline
Junior Poster
 
0
  #5
Nov 6th, 2009
thank you so.....much for your help........mr.pritaeas. i have no words to wish. thanks a lot.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 128
Reputation: muralikalpana is an unknown quantity at this point 
Solved Threads: 7
muralikalpana's Avatar
muralikalpana muralikalpana is offline Offline
Junior Poster
 
0
  #6
Nov 6th, 2009
in this we can not group check boxes. so how can we select onlyone from two check boxes in the case of 'OR' case. for example checkbox1 (or)checkbox2. in this case we have to select only one checkbox. if one checkbox checked automatically other will be in uncheck.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 185
Reputation: venkat0904 is an unknown quantity at this point 
Solved Threads: 19
venkat0904's Avatar
venkat0904 venkat0904 is offline Offline
Junior Poster
 
0
  #7
Nov 6th, 2009
you are looking for a radio button not a check box. Only one radio button gets selected from a defined group.
Just define each radio button in a specific group under the same "name" attribute. eg: option1 name="group1" option2 name="group1" option 3 name="group2"
above example lets you choose only 1 out of option 1 and 2 but lets u select option 3 simultaneously

Originally Posted by muralikalpana View Post
in this we can not group check boxes. so how can we select onlyone from two check boxes in the case of 'OR' case. for example checkbox1 (or)checkbox2. in this case we have to select only one checkbox. if one checkbox checked automatically other will be in uncheck.
Last edited by venkat0904; Nov 6th, 2009 at 5:04 am.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 128
Reputation: muralikalpana is an unknown quantity at this point 
Solved Threads: 7
muralikalpana's Avatar
muralikalpana muralikalpana is offline Offline
Junior Poster
 
0
  #8
Nov 6th, 2009
Originally Posted by venkat0904 View Post
you are looking for a radio button not a check box. Only one radio button gets selected from a defined group.
Just define each radio button in a specific group under the same "name" attribute. eg: option1 name="group1" option2 name="group1" option 3 name="group2"
above example lets you choose only 1 out of option 1 and 2 but lets u select option 3 simultaneously
k. for suppse we have two checkboxes is there .we have to select one check box from that. so how can?
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 185
Reputation: venkat0904 is an unknown quantity at this point 
Solved Threads: 19
venkat0904's Avatar
venkat0904 venkat0904 is offline Offline
Junior Poster
 
0
  #9
Nov 6th, 2009
i think u didnt get me... checkboxes are meant for multiple selection... 1 checkbox is not supposed to be influenced by selection of other but radio buttons are meant to do so... like wen u need to select a gender u use a radio button coz u dont want both male n female to b selected..

Originally Posted by muralikalpana View Post
k. for suppse we have two checkboxes is there .we have to select one check box from that. so how can?
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 128
Reputation: muralikalpana is an unknown quantity at this point 
Solved Threads: 7
muralikalpana's Avatar
muralikalpana muralikalpana is offline Offline
Junior Poster
 
0
  #10
Nov 6th, 2009
Originally Posted by venkat0904 View Post
i think u didnt get me... checkboxes are meant for multiple selection... 1 checkbox is not supposed to be influenced by selection of other but radio buttons are meant to do so... like wen u need to select a gender u use a radio button coz u dont want both male n female to b selected..
k.......i know that point. but have you see some examples like this...................."you have to select only 2choices from multiple checkboxes". there is 7 boxes is there but select 2choices only. k. got the point?
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC