thomashw Posted March 20, 2008 Share Posted March 20, 2008 I have the "options" of a "select" form being populated by a 'for' loop after querying a database to see how many options are there for the specific page. What I want to do is pass more than one value depending on which option the user selects. I already have one value being passed by the means of "<option name="name" value="value"..." but I'd like to pass another value as well. I tried adding a "hidden" input in the form loop to be populated as well, but this just passes all the values in the database - not just the one corresponding to what the user selected. Anyone have any good ideas for passing more than one value depending on what a user selects in a drop-down box? Quote Link to comment https://forums.phpfreaks.com/topic/97075-passing-multiple-values/ Share on other sites More sharing options...
Perad Posted March 20, 2008 Share Posted March 20, 2008 You could set the value as... value1|value2 Then use the explode() function separate them later on. Quote Link to comment https://forums.phpfreaks.com/topic/97075-passing-multiple-values/#findComment-496727 Share on other sites More sharing options...
pocobueno1388 Posted March 20, 2008 Share Posted March 20, 2008 You could separate each value by a delimiter, then explode() it when you use the data. So, something like this: <select> <option value="value1-value2-value3"> <option value="value1-value2"> </select> Give more information on what values your trying to pass, and why you need the multiple values. There could be a better way. Quote Link to comment https://forums.phpfreaks.com/topic/97075-passing-multiple-values/#findComment-496729 Share on other sites More sharing options...
laffin Posted March 20, 2008 Share Posted March 20, 2008 Working with an option/select box is same as working with checkboxes just define the name with the array square brackets. here is a sample I use to demonstrate (modified with select/option) <?php if($_SERVER['REQUEST_METHOD']=='POST') { if(isset($_POST['cb'])) { $cb=implode(',',$_POST['cb']); } echo "cb = '$cb'<BR>"; if(isset($_POST['sb'])) { $sb=implode(',',$_POST['sb']); } echo "sb = '$sb'<BR>"; } ?> <form method="POST"> <select name="sb[]" multiple="true"> <option value="0">Zero</option> <option value="1">One</option> <option value="2">Two</option> <option value="3">Three</option> </select> 0<INPUT TYPE='checkbox' name='cb[]' value='0'> 1<INPUT TYPE='checkbox' name='cb[]' value='1'> 2<INPUT TYPE='checkbox' name='cb[]' value='2'> 3<INPUT TYPE='checkbox' name='cb[]' value='3'> 4<INPUT TYPE='checkbox' name='cb[]' value='4'> <INPUT type="submit"> </FORM> Quote Link to comment https://forums.phpfreaks.com/topic/97075-passing-multiple-values/#findComment-496761 Share on other sites More sharing options...
thomashw Posted March 21, 2008 Author Share Posted March 21, 2008 Thanks for the help everyone. I used the explode function and it worked beautifully. I hadn't even thought of that! Quote Link to comment https://forums.phpfreaks.com/topic/97075-passing-multiple-values/#findComment-497495 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.