943,097 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 2048
  • PHP RSS
Feb 9th, 2010
0

how to post the selected checkbox values

Expand Post »
hi friends
I have using four the checkboxes in check.htm form . The selected checkbox values will be posted in the enquiry text box field of the enquiry.php file. but i didnt post the selected checkbox values in that field.
please can u give suggestion. how to solve this,

check.htm

PHP Syntax (Toggle Plain Text)
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2. "http://www.w3.org/TR/html4/loose.dtd">
  3. <html>
  4. <head>
  5. <title>Untitled Document</title>
  6. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  7. <script>
  8. function chk_unchk(val, form_name) {
  9. dml=eval('document.'+form_name);
  10. len=dml.elements.length;
  11. var i=0;
  12. for (i=0; i<len; i++) {
  13. if (dml.elements[i].type == "checkbox") {
  14. if (val == 1) {
  15. dml.elements[i].checked=true;
  16. }
  17. else {
  18. dml.elements[i].checked=false;
  19. }
  20. }
  21. }
  22. }
  23. function SubmitCheckForm()
  24. {
  25. frmCheckform = document.Checkform;
  26. // assigh the name of the checkbox;
  27. var chks = document.getElementsByName('cashewnut[]');
  28.  
  29. var hasChecked = false;
  30. // Get the checkbox array length and iterate it to see if any of them is selected
  31. for (var i = 0; i < chks.length; i++)
  32. {
  33. if (chks[i].checked)
  34. {
  35. hasChecked = true;
  36. break;
  37. }
  38. }
  39. // if ishasChecked is false then throw the error message
  40. if (!hasChecked)
  41. {
  42. alert("Please select at least one product.");
  43. chks[0].focus();
  44. return false;
  45. return true;
  46. }
  47. // if one or more checkbox value is selected then submit the form
  48. return confirm("Are you sure to add this product list(s)?");
  49. //if(booSubmit == true)
  50. // frmdryfruits.submit();
  51.  
  52. }
  53. </script>
  54. </head>
  55.  
  56. <body>
  57. <form name="form1" action="enquiry.php" method="post" onSubmit="return SubmitCheckForm();">
  58. <table>
  59. <tr>
  60. <td>cashewkernal</td><td><input type="checkbox" style="height: 17px;" value="kernels" name="cashewnut[]" id="cashew1"/>
  61. </td>
  62. <td>Flavoured cashew</td><td>
  63. <input type="checkbox" style="height: 17px;" value="flavouured cashew" name="cashewnut[]" id="cashew2"/>
  64. </td>
  65. <td>Raw cashew</td><td>
  66. <input type="checkbox" style="height: 17px;" value="rawcashew" name="cashewnut[]" id="cashew3"/>
  67. </td>
  68. <td>cashewnut</td><td>
  69. <input type="checkbox" style="height: 17px;" value="cashewnut" name="cashewnut[]" id="cashew4"/>
  70. </td>
  71. </tr>
  72. <tr><td><input type="submit" value="submit" name="Enquiry" value="Enquiry" ></td></tr>
  73. </table>
  74. </form>
  75. </body>
  76. </html>

Enquiry.php
PHP Syntax (Toggle Plain Text)
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <head>
  4. <title>Untitled Document</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  6. </head>
  7. <body>
  8. <?php
  9. if(isset($_POST['cashewnut'])){
  10. $cashew = $_POST['cashewnut'];
  11. $n = count($cashew);
  12. $i = 0;
  13. echo " <p align='left'><b>Your selected products are</b>: " ."<table><tr><td>";
  14. while ($i < $n) {
  15. echo "<input type='checkbox' checked='checked'>{$cashew[$i]} ";
  16. $i++;
  17. }
  18. echo "</td></tr></table></p>";
  19. }
  20. ?>
  21. <table width="200" border="0">
  22. <tr>
  23. <td>Name : </td><td><input type="text" name="name"><br></td>
  24. </tr>
  25. <tr>
  26. <td>Comp. Name : </td><td><input type="text" name="companyname"><br></td>
  27. </tr>
  28. <tr>
  29. <td>Address : </td><td><input type="text" name="address"><br></td>
  30. </tr>
  31. <tr>
  32. <td>Country : </td><td><input type="text" name="country"><br></td>
  33. </tr>
  34. <tr>
  35. <td>Email : </td><td><input type="text" name="email"><br></td>
  36. </tr>
  37. <tr>
  38. <td>Phone : </td><td><input type="text" name="phone"><br></td>
  39. </tr>
  40. <tr>
  41. <td align="left">Enquiry </td>
  42. <td align="left"><input type="text" name="enquiry" value="<?php echo $_POST['cashewnut'];?>" onBlur="checktextbox(this);"/>&nbsp;<span id="enquiryerror"></field></td>
  43. </tr>
  44. <tr>
  45. <td>Details : </td> <td><input type="text" name="details"><br></td>
  46. </tr>
  47. <tr>
  48. <td><INPUT class="button" type="submit" name="submit" value="Submit"></td>
  49. <td> </td>
  50. </tr>
  51. </table>
  52. </body>
  53. </html>
Last edited by adatapost; Feb 9th, 2010 at 8:40 am. Reason: Added [code] tags. Encase your code in: [code] and [/code] tags.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sunaruna84 is offline Offline
19 posts
since Mar 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: bank wire transfer
Next Thread in PHP Forum Timeline: correction of code plz





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


Follow us on Twitter


© 2011 DaniWeb® LLC