doforumda Posted June 14, 2011 Share Posted June 14, 2011 hi, I am trying to use checkboxes with jquery and php. I am submitting checkboxes to php file using jquery. but what I want to do is to get checked checkboxes and send to php file and display all the checked values. Here is my current code <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script type="text/javascript" src="jquery-lib.js"></script> <script> $(function() { $('#submit').click(function() { var inp = $('input:checkbox').val(); //alert(inp); var url = 'test1process.php?inp=' + inp; $(location).attr('href',url); }); }); </script> </head> <body> <input type="checkbox" name="checkbox[]" id="checkbox" value="a" />A<br /> <input type="checkbox" name="checkbox[]" id="checkbox" value="b" />B<br /> <input type="checkbox" name="checkbox[]" id="checkbox" value="c" />C<br /> <input type="checkbox" name="checkbox[]" id="checkbox" value="d" />D<br /> <input type="checkbox" name="checkbox[]" id="checkbox" value="e" />E<br /> <input type="checkbox" name="checkbox[]" id="checkbox" value="f" />F<br /> <input type="checkbox" name="checkbox[]" id="checkbox" value="g" />G<br /> <input type="button" name="submit" id="submit" value="Submit" /> </body> </html> here php file <?php $inp = $_GET['inp']; if(count($inp) > 0) { for($i = 0; $i < count($inp); $i++) { echo "Value: $inp[$i]<br>"; } } ?> please help! Quote Link to comment https://forums.phpfreaks.com/topic/239324-need-help-with-checkboxes/ Share on other sites More sharing options...
cyberRobot Posted June 14, 2011 Share Posted June 14, 2011 I'm not very familiar with jQuery, but I would imagine you still need to add the <form> tag around your form elements. Quote Link to comment https://forums.phpfreaks.com/topic/239324-need-help-with-checkboxes/#findComment-1229469 Share on other sites More sharing options...
doforumda Posted June 14, 2011 Author Share Posted June 14, 2011 Yea I know it would be easy but I making these input form fields dynamically using php's echo. this is just demo to get help. here is how i am making that form right now if(!($_SESSION['userid'] && $_SESSION['username'])) { header("Location: error.php"); } else { echo "<button name='edit' id='edit'>Edit</button>"; echo "<button name='delete' id='delete'>Delete</button>"; echo "<button name='addAttorney' id='addAttorney'>Add Attorney</button>"; echo "<table cellpadding='2' border='0'>"; echo "<tr>"; //start of the titles row echo "<td></td>"; echo "<td><b>Name</b></td>"; echo "<td><b>Email</b></td>"; echo "<td><b>Address</b></td>"; echo "<td><b>Mobile Number</b></td>"; echo "<td><b>Validity</b></td>"; echo "<td><b>Code</b></td>"; echo "</tr>"; // end of the titles row $get_poa = mysql_query("SELECT * FROM permanentattorneyinfo WHERE userid='$_SESSION[userid]'"); if(mysql_numrows($get_poa) > 0) { while($row = mysql_fetch_assoc($get_poa)) { $attorneyName = $row['nameOfAttorney']; $attorneyAddress = $row['addressOfAttorney']; $attorneyMobile = $row['mobileOfAttorney']; $attorneyEmail = $row['emailOfAttorney']; $validFrom = $row['validFrom']; $validTo = $row['validTo']; $code = $row['poaCode']; echo "<tr class='lightgrey'>"; //start of the data row echo "<td><input type='checkbox' name='delete[]' value='$attorneyName' /></td>"; echo "<td>$attorneyName</td>"; echo "<td>$attorneyEmail</td>"; echo "<td>$attorneyAddress</td>"; echo "<td>$attorneyMobile</td>"; echo "<td>$validFrom - $validTo</td>"; echo "<td>$code</td>"; echo "</tr>"; // end of the data row } echo "</table>"; //End of table } else { echo "You do not choose power of attorney yet!"; } } Quote Link to comment https://forums.phpfreaks.com/topic/239324-need-help-with-checkboxes/#findComment-1229481 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.