Page 1 of 1

How can i remember the selected value from listmenu?

Posted: Mon Oct 12, 2009 12:10 am
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.....

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

Posted: Wed Oct 14, 2009 2:25 am
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

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

Posted: Wed Oct 14, 2009 3:13 am
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'.
}
 
?>