Page 1 of 1
dumb problem i can't get through.
Posted: Mon Jan 12, 2009 8:37 am
by koguee
I don't know how I would access the value of value="" in the <select> form.
I have this code:
<select name="something" method="post">
<option value="value1">name</option>
<option value="value2">name2</option>
...
...
</select>
now, this select form is inside a form with many more
<select>s and other <input>s with it.
my problem is, how I can access value1,value2 from that certain <select> form through
plain PHP. Do I need to use $_POST?
Re: dumb problem i can't get through.
Posted: Mon Jan 12, 2009 8:42 am
by papa
<form method=post>
$_POST['something']
Re: dumb problem i can't get through.
Posted: Mon Jan 12, 2009 8:45 am
by jaoudestudios
<select name="something" method="post">
<option value="value1">name</option>
<option value="value2">name2</option>
This wrong. You will need to read up on basic html. This should give you a step in the right direction...
Code: Select all
<form action='#' method='post'>
<select name='result1' id='result1'>
<option value='1'>1</option>
<option value='2'>2</option>
<option value='3'>3</option>
</select>
</form>
Code: Select all
<?php
echo $_POST['result1']; // this will display the option value that the user selected
?>
Re: dumb problem i can't get through.
Posted: Mon Jan 12, 2009 8:57 am
by koguee
as far as i know,
you can actually create something like this:
Code: Select all
<select name="something">
<option value="name">not name</option>
</select>
Now, I want php to get the value of value=""
and not what's between the <option> tags.
would $_POST['something'] automatically return
what the option's value, for this case,
would it return
name?

Re: dumb problem i can't get through.
Posted: Mon Jan 12, 2009 9:01 am
by jaoudestudios
Try it and see
But yes it would return name. If you dont put value attribute on the option, it will return what is between the option tags, but if you use the value attribute, it will return the value of that - in this case
name
Re: dumb problem i can't get through.
Posted: Tue Jan 13, 2009 2:42 am
by koguee
jaoudestudios wrote:Try it and see
But yes it would return name. If you dont put value attribute on the option, it will return what is between the option tags, but if you use the value attribute, it will return the value of that - in this case
name
thank you. I was also enlightened by my web programming subject with regard to that very particular detail.