I have two buttons named 'go' and 'sub' and one form to do this.At same form i have two click events.
echo "<input type='submit' name='go' id='go' value='Go' />"; // button go
echo "<input type="submit" name="sub" id="button" value="Submit" />"; // button sub
echo "<input type='text' name='type' id='type' value='$router' />"; // This is a texbox. This value-$router pass from a list box
if (isset($_POST['go'])) // when user click on go button
{
$r=$_POST['type'];
echo $r; // this printed $r value.
}
if (isset($_POST['sub']))
{
// problem is...
// How can i get $r value to here...?
echo "Router : ".$r; // I got null value for this
// How can i get $r value to this click event..?
}
How can I pass a veriable -----
Moderator: General Moderators
Re: How can I pass a veriable -----
Because your $r variable is created within a set of braces ( {} ), it is only accessible within those braces. You either need to define it outside of your 'if' statement, or define it within each set of braces. The first method is neater IMHO:
On a minor point of efficiency, since only one of the two submit buttons can be pressed for a particular request, it's nicer to use an 'if...elseif' statement than two 'if's.
Code: Select all
if(isset($_POST['go']) || isset($_POST['sub']) {
$r = $_POST['type'];
if (isset($_POST['go'])) {
echo $r; // this printed $r value.
} elseif(isset($_POST['sub'])) {
echo "Router : ".$r; // I got null value for this
}
}
Re: How can I pass a veriable -----
Thank you dear friend.....really thank you.....
if i have a listbox instead of textbox how can Listbox remember that user selected Item..?
I have a ListMenu names MyListBox.
<select name="MyListMenu" id="MyListMenu">
<option>a</option>
<option>b</option>
<option>c</option>
</select>
<input type="submit" name="button" id="button" value="Submit" />
If i select Item 'b' from MyListMenu and click on button, I wanna remaining (remember) item 'b' on MyListMenu after click on the Button.
How can i do this..?
Thank you...
if i have a listbox instead of textbox how can Listbox remember that user selected Item..?
I have a ListMenu names MyListBox.
<select name="MyListMenu" id="MyListMenu">
<option>a</option>
<option>b</option>
<option>c</option>
</select>
<input type="submit" name="button" id="button" value="Submit" />
If i select Item 'b' from MyListMenu and click on button, I wanna remaining (remember) item 'b' on MyListMenu after click on the Button.
How can i do this..?
Thank you...