Page 1 of 1

$_POST an OPTION value?

Posted: Fri Mar 26, 2010 2:18 pm
by synical21
I am trying to post the value of a <select> field, I have googled around but my problem gets worse rather than better. Here is the current code:

Code: Select all

 
<SELECT onChange="final_cat_and_price()" SIZE=9 NAME=Sub Id=Sub>
<OPTION value=0000>Click 2x</OPTION>
<OPTION value=0001>Click 3x</OPTION>
<OPTION value=0002>Search + Click 1x</OPTION>
<OPTION value=0003>Search + Click 2x</OPTION>
</SELECT>
<SELECT onChange="final_cat_and_price()" SIZE=9 NAME=Sub Id=Sub>
<OPTION value=0200>1 Page</OPTION>
<OPTION value=0201>2 Pages</OPTION>
<OPTION value=0202>3 Pages</OPTION>
<OPTION value=0203>4 Pages</OPTION>
</SELECT>
 
As you can see each option has a value, how could i post that value to a new page so i can use the data?

Re: $_POST an OPTION value?

Posted: Fri Mar 26, 2010 2:27 pm
by Trahb
There's probably a better way, but I store the value in a variable of one of my classes and call it on the other page.

Re: $_POST an OPTION value?

Posted: Fri Mar 26, 2010 3:33 pm
by AbraCadaver
Are you asking how you post it? Or how do you access it on the next page or what?

Re: $_POST an OPTION value?

Posted: Fri Mar 26, 2010 4:16 pm
by synical21
how I would access it on another page, then insert the value into the DB. My bad

Re: $_POST an OPTION value?

Posted: Fri Mar 26, 2010 8:44 pm
by Alkis
You need to include the form fields inside a <form> tag, to actually have a working form watch the -> action="anotherpage.php" <- witch actually informs the browser where to post the data inside the form. Rename it to what to receiving page is. Note also a new button entry, the "Submit". This will be the button which will actually post the form to the "action" page.

Code: Select all

<form name="form1" action="anotherpage.php" method="post">
 
<SELECT onChange="final_cat_and_price()" SIZE=9 NAME=Sub Id=Sub>
<OPTION value=0000>Click 2x</OPTION>
<OPTION value=0001>Click 3x</OPTION>
<OPTION value=0002>Search + Click 1x</OPTION>
<OPTION value=0003>Search + Click 2x</OPTION>
</SELECT>
 
<input type="submit" value="Submit" />
 
</form>

And then on anotherpage.php you will get the the selected value from the Sub select and assign it to the $sub variable, and do with it what you want:

$sub = $_POST['Sub'];