-
January 15th, 2007, 09:07 AM
#1
Getting selected values in multi select comobo box through PHP
Hi,
I have the following HTML code right now.
Code:
<td width="20%"><SELECT NAME="cfg_input_global_report_types" MULTIPLE >
<OPTION VALUE="BU" >Option1
<OPTION VALUE="BP" >Option2
<OPTION VALUE="BC" >Option3
<OPTION VALUE="BL" >Option4
<OPTION VALUE="BCC">Option5
</SELECT></td>
The form is submitted using POST method
I know how to use the $_POST php function to get the "cfg_input_global_report_types" variable
Code:
$_POST["cfg_input_global_report_types"]
But I don't know how the selected variables are formatted in the $_POST["cfg_input_global_report_types"] variable. If anybody could show me how the selected values are formated in the above variable it would be great.
Or if this method doesn't work at all or if there is a more easy way, how can I get the selected values in my multiple select combo box.
Thanx in advance.
If there is no love sun won't shine
-
January 15th, 2007, 09:49 AM
#2
Re: Getting selected values in multi select comobo box through PHP
The code you posted will grab the value of the <SELECT> that is selected at the time of form submission. Are you attempting to get all the <OPTION> tags values? Is so, you can't do it without making a hidden <DIV> and having JavaScript put those in there for you.
PHP Code:
$_POST["cfg_input_global_report_types"]
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
January 15th, 2007, 10:00 AM
#3
Re: Getting selected values in multi select comobo box through PHP
Originally Posted by PeejAvery
The code you posted will grab the value of the <SELECT> that is selected at the time of form submission. Are you attempting to get all the <OPTION> tags values?
Hi PeejAvery, I don't need to get all the <OPTION> tag values. I simply want to get the values that is selected by the user at the time of form submission.
With simple select it was not a problem. I can simply use the $_POST with the select's name. But with multiple select there could be several values that maybe selected by the user when submitting the form.
So my question is:
How the multiple selected values will be inside the $_POST["cfg_input_global_report_types"]. Will they be comma separated or will it be an array?
If there is no love sun won't shine
-
January 15th, 2007, 10:13 AM
#4
Re: Getting selected values in multi select comobo box through PHP
I wouldn't know off hand? But couldn't you just create a simple script and see what the output is ... ?
*9-11-01* Never Forget; Never Forgive; Never Relent!
"If we ever forget that we're one nation under God, then we will be a nation gone under." - Ronald Reagan
-
January 15th, 2007, 10:28 AM
#5
Re: Getting selected values in multi select comobo box through PHP
Originally Posted by Dr. Script
I wouldn't know off hand? But couldn't you just create a simple script and see what the output is ... ?
Thanx for the suggestion. I will try it. I will echo it.
Till now I have been filling the values directly to my MySQL database, and the corresponding field comes to be empty.
If there is no love sun won't shine
-
January 15th, 2007, 10:45 AM
#6
Re: Getting selected values in multi select comobo box through PHP
I find this strange:
When I select 3 out of 5 possible values, the echo output of the variable is the last item that has been selected. The count php function returns 1 idicating that it is not an array. Where are the other selected values. How can I get it. Googled the entire net but couldn't find a solution.
If there is no love sun won't shine
-
January 15th, 2007, 10:58 AM
#7
Re: Getting selected values in multi select comobo box through PHP
Wait, you don't have to do anything if it is a multiple select box. The PHP will process it as an array.
You have to make the <SELECT> an array.
Code:
<?php
if(isset($_POST['selectbox'])){
print_r($_POST['selectbox']);
exit;
}
?>
<form action="" method="post">
<select name="selectbox[]" multiple>
<option value="a">a</option>
<option value="b">b</option>
<option value="c">c</option>
<option value="d">d</option>
<option value="e">e</option>
<option value="f">f</option>
<option value="g">g</option>
<option value="h">h</option>
<option value="i">i</option>
<option value="j">j</option>
<option value="k">k</option>
</select>
<input type="submit" value="Submit">
</form>
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
January 15th, 2007, 11:21 AM
#8
Re: Getting selected values in multi select comobo box through PHP
Splendid! PeejAvery Thanx a lot. Searched the net for at least 2 hours.
If there is no love sun won't shine
-
January 15th, 2007, 11:45 AM
#9
Re: Getting selected values in multi select comobo box through PHP
You're welcome. I haven't used multiple <select> tags for years. Good luck with the rest!
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
January 16th, 2007, 03:29 AM
#10
Re: Getting selected values in multi select comobo box through PHP
Set your form variable as array.
<select name="var_name[]">
<option value="1">1</option>
.
.
</select>
<?php
print_r($_post['var_name']);
?>
-
January 16th, 2007, 10:16 AM
#11
Re: Getting selected values in multi select comobo box through PHP
@nes2rmp. Please read the whole thread before posting. The answer has already been provided and the problem solved. We don't want to flood the forum with useless posts.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
January 17th, 2007, 12:55 AM
#12
Re: Getting selected values in multi select comobo box through PHP
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|