kadamsurekha Posted March 28, 2007 Share Posted March 28, 2007 hello! i hav a dynamic checkbox array. i want to know, out of all which are selected and if selected then i am inserting the selected checkbox value in the table field. my code is as follows:- $no=0; $friendname= $_POST['friendname']; $storecount=$_POST['storeid']; while($no<$storecount) { if($friendname[$no]) { $sql = "INSERT INTO groupfriends (groupid, username) VALUES ('$stid[$no]', '$friendname[$no]')"; $result = mysql_query($sql) or die('Query failed. ' . mysql_error()); } $no=$no+1; } the code adds all the checkboxes. i want to add only those checkboxes which r selected. can any1 help me plse??????? thx n regards Quote Link to comment Share on other sites More sharing options...
suzzane2020 Posted March 28, 2007 Share Posted March 28, 2007 call this javascript on the click event of the submit button function MM_callJS() { document.form1.chkIds.value=document.form1.links.value for (i=0; i<document.form1.links.length; i++){ if (document.form1.links[i].checked==true) { document.form1.chkIds.value=document.form1.chkIds.value+","+document.form1.links[i].value } } return true; } In this example te checkbox has a name 'links' and a hidden field named chkIds. on form submit the values of the selected boxes are passed to the hidden field. This value neds to be exploded with ',' Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted March 28, 2007 Share Posted March 28, 2007 your code is way off bud. but before we can help you, we need to know what you're trying to do... what is friend name and what is storeid, and how are they related? what are their values? Quote Link to comment 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.