How can i remember the selected value from listmenu?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
dilruk83
Forum Newbie
Posts: 13
Joined: Thu Oct 30, 2008 6:44 am

How can i remember the selected value from listmenu?

Post by dilruk83 »

I have a buttons named 'button1' and one Listmenu named listmenu1. All those button and Listmenu are in one form named form1

<?php

echo "<input type='submit' name='button1' id='button1' value='Go' />"; // button1
echo "<select name="listmenu1" id="listmenu1">
<option>a</option>
<option>b</option>
<option>c</option>
</select>"; .// listmenu1

if (isset($_POST['button1'])) // when user click on button1, button
{
$value=$_POST['listmenu1']; // get the selected value from listmenu1.assume that I selected b from listmenu1'.
}

?>

After click on the button1 I want to remaining the selected value of listmenu1.

If user select b from listmenu1 and click on button1,then listmenu1 should be selected as b.

How can i do this..?


thanking u all.....
godwinsam
Forum Newbie
Posts: 9
Joined: Wed Sep 16, 2009 11:01 pm

Re: How can i remember the selected value from listmenu?

Post by godwinsam »

Hello,

Please put the following code and check it,

<?php
echo "<form name='form1' action='' method='post'>";
echo "<input type='submit' name='button1' id='button1' value='Go' />"; // button1
echo "<select name='listmenu1' id='listmenu1'>
<option>a</option>
<option>b</option>
<option>c</option>
</select></form>"; // listmenu1

if (isset($_POST['button1'])) // when user click on button1, button
{
$value=$_POST['listmenu1']; // get the selected value from listmenu1.assume that I selected b from listmenu1'.
echo $value;// print the selected value from listmenu1
}

?>

Thanks & Regards
Turv
Forum Commoner
Posts: 25
Joined: Fri Mar 13, 2009 3:56 pm

Re: How can i remember the selected value from listmenu?

Post by Turv »

dilruk83 wrote:I have a buttons named 'button1' and one Listmenu named listmenu1. All those button and Listmenu are in one form named form1

<?php

echo "<input type='submit' name='button1' id='button1' value='Go' />"; // button1
echo "<select name="listmenu1" id="listmenu1">
<option>a</option>
<option>b</option>
<option>c</option>
</select>"; .// listmenu1

if (isset($_POST['button1'])) // when user click on button1, button
{
$value=$_POST['listmenu1']; // get the selected value from listmenu1.assume that I selected b from listmenu1'.
}

?>

After click on the button1 I want to remaining the selected value of listmenu1.

If user select b from listmenu1 and click on button1,then listmenu1 should be selected as b.

How can i do this..?


thanking u all.....
You need to give your Select box values, like so.

Code: Select all

 
<?php
 
echo "<input type='submit' name='button1' id='button1' value='Go' />"; // button1
echo "<select name="listmenu1" id="listmenu1">
    <option value="a">a</option>
    <option value="b">b</option>
    <option value="c">c</option>
  </select>"; .// listmenu1
 
if (isset($_POST['button1']))  // when user click on button1, button
{
    // Now $value is equal to whatever option was selected.
    $value=$_POST['listmenu1']; // get the selected value from listmenu1.assume that I selected  b from listmenu1'.
}
 
?>
Post Reply