944,141 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1065
  • PHP RSS
You are currently viewing page 1 of this multi-page discussion thread
Nov 6th, 2009
-1

chechbox validations

Expand Post »
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.
PHP Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 21
Solved Threads: 35
Posting Pro
muralikalpana is offline Offline
534 posts
since Sep 2009
Nov 6th, 2009
0
Re: chechbox validations
Found this link, and made it into this:
http://expressionengine.com/forums/viewthread/128806/

PHP Syntax (Toggle Plain Text)
  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
Sponsor
Featured Poster
Reputation Points: 557
Solved Threads: 735
Bite my shiny metal ass!
pritaeas is offline Offline
4,204 posts
since Jul 2006
Nov 6th, 2009
0
Re: chechbox validations
how to call this function from form
Reputation Points: 21
Solved Threads: 35
Posting Pro
muralikalpana is offline Offline
534 posts
since Sep 2009
Nov 6th, 2009
0
Re: chechbox validations
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...
Sponsor
Featured Poster
Reputation Points: 557
Solved Threads: 735
Bite my shiny metal ass!
pritaeas is offline Offline
4,204 posts
since Jul 2006
Nov 6th, 2009
0
Re: chechbox validations
thank you so.....much for your help........mr.pritaeas. i have no words to wish. thanks a lot.
Reputation Points: 21
Solved Threads: 35
Posting Pro
muralikalpana is offline Offline
534 posts
since Sep 2009
Nov 6th, 2009
-1
Re: chechbox validations
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.
Reputation Points: 21
Solved Threads: 35
Posting Pro
muralikalpana is offline Offline
534 posts
since Sep 2009
Nov 6th, 2009
0
Re: chechbox validations
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

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.
Reputation Points: 13
Solved Threads: 21
Junior Poster
venkat0904 is offline Offline
186 posts
since Oct 2009
Nov 6th, 2009
-1
Re: chechbox validations
Click to Expand / Collapse  Quote originally posted by venkat0904 ...
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?
Reputation Points: 21
Solved Threads: 35
Posting Pro
muralikalpana is offline Offline
534 posts
since Sep 2009
Nov 6th, 2009
0
Re: chechbox validations
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. for suppse we have two checkboxes is there .we have to select one check box from that. so how can?
Reputation Points: 13
Solved Threads: 21
Junior Poster
venkat0904 is offline Offline
186 posts
since Oct 2009
Nov 6th, 2009
0
Re: chechbox validations
Click to Expand / Collapse  Quote originally posted by venkat0904 ...
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?
Reputation Points: 21
Solved Threads: 35
Posting Pro
muralikalpana is offline Offline
534 posts
since Sep 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 PHP Forum Timeline: png image croping problem
Next Thread in PHP Forum Timeline: refresh part of the page





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


Follow us on Twitter


© 2011 DaniWeb® LLC