dumb problem i can't get through.

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
koguee
Forum Newbie
Posts: 18
Joined: Thu Aug 14, 2008 5:13 am
Location: Philippines
Contact:

dumb problem i can't get through.

Post 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?
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: dumb problem i can't get through.

Post by papa »

<form method=post>

$_POST['something']
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: dumb problem i can't get through.

Post 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
?>
koguee
Forum Newbie
Posts: 18
Joined: Thu Aug 14, 2008 5:13 am
Location: Philippines
Contact:

Re: dumb problem i can't get through.

Post 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?
:)
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: dumb problem i can't get through.

Post 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
koguee
Forum Newbie
Posts: 18
Joined: Thu Aug 14, 2008 5:13 am
Location: Philippines
Contact:

Re: dumb problem i can't get through.

Post 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.
Post Reply