cmccully Posted October 27, 2006 Share Posted October 27, 2006 Hi, I have a dynamically generated form with several checkboxes. The checkboxes are referenced by number, such as cb_1, cb_4, cb_25 etc... What I want to know is the number associated with the checkbox or boxes that were selected. How can I parse the names of the form variables submited to extract the number(s) that referenced the selected checkboxes?cmccully Quote Link to comment Share on other sites More sharing options...
redarrow Posted October 27, 2006 Share Posted October 27, 2006 Heres a little example for you ok.in this example the user wants to buy somethink in this case its water but then we change the water to a fish.good luck. [code]<form method="POST" action=""><br>do you want to buy a coffe<br><input type="checkbox" name="description[]" value="coffe"><br>do you want to buy a tea<br><input type="checkbox" name="description[]" value="tea"><br>do you want to buy a coke<br><input type="checkbox" name="description[]" value="coke"><br>do you want to buy water<br><input type="checkbox" name="description[]" value="water"><br><br><input type="submit" name="submit" value="buy now!"></form><?phpif($_POST['submit']){foreach($description as $x){if($x=="water"){$x="fish";}echo "<br>I would like to have a $x <br>";} }?>[/code] Quote Link to comment Share on other sites More sharing options...
sasa Posted October 27, 2006 Share Posted October 27, 2006 try[code]<?php$data = array( array(id => 1, 'name' => 'asd'), array(id => 2, 'name' => 'qwe'), array(id => 3, 'name' => 'xcv'), array(id => 4, 'name' => 'mko') );echo '<form method="POST">';foreach ($data as $a) echo '<input type="checkbox" name="ch['.$a['id'].']" value="'.$a['name'].'">'.$a['name'].'<br />';echo '<input type="submit"></form>';if(isset($_POST['ch'])) foreach ($_POST['ch'] as $key => $value) echo "ch box no $key with value $value is selected<br />";?>[/code] Quote Link to comment Share on other sites More sharing options...
cmccully Posted October 27, 2006 Author Share Posted October 27, 2006 That's it redarrow, that's exactly what I need. Thankscmccully 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.