Get value from Select menu

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
md7dani
Forum Newbie
Posts: 13
Joined: Fri Oct 23, 2009 1:55 am

Get value from Select menu

Post by md7dani »

Hi!

Have tried to find the solution on the web. Don't know if there is an easy one. A description:

Code: Select all

<form method="post" name="me" action="http://chart.apis.google.com/chart?cht=lc&chd=t:30,35,36&chxt=x,y,r&chl=:<? echo $month_arr[0]; ?>|<? echo $month_arr[1]; ?>|<? echo $month_arr[2]; ?>">
 
<select name="month_sel" id="month" style="width: 50px;">
    <option value="3">3 months</option>
    <option value="6">6 months</option>
    <option value="3" SELECTED>3 months</option>
  </select>
<?php $first_month = $month-$s; 
$month_arr[0] = $first_month;
.
.
?>
<input type="submit" value="submit" name="submit">
</form>
 
The thing is that I want to pass the value from the selected option in the menu into $s. Then pass the array to the Form action tag. Is this possible maybe with a return function?
I know how to get the value with javascript and OnChange but don't know how to use it.

Thanks.
User avatar
markusn00b
Forum Contributor
Posts: 298
Joined: Sat Oct 20, 2007 2:16 pm
Location: York, England

Re: Get value from Select menu

Post by markusn00b »

You are POSTing the data, so any information in the form is available via the $_POST array.

Code: Select all

echo $_POST['month_sel'];
md7dani
Forum Newbie
Posts: 13
Joined: Fri Oct 23, 2009 1:55 am

Re: Get value from Select menu

Post by md7dani »

markusn00b wrote:You are POSTing the data, so any information in the form is available via the $_POST array.

Code: Select all

echo $_POST['month_sel'];
thanks,
Tried it but it didn't work, don't know why. I've read that the information in the form is only available when submitting the data. I need to use the data before submit button is pressed. I will check it again, maybe I missed something.
Post Reply