Page 1 of 1
Issue with PHP combo box select and d an action
Posted: Thu May 28, 2009 2:15 am
by mana_panigrahi
Hi ALL,
I am new to php.
I am trying to create a combo box in php and if any of the item in combo box is selected some action should happen.
Ex code:
Code: Select all
<?php
echo "<select name='jack'>";
echo "<option value= Release>Release</option>";
echo "<option value=ReleaseWithData>ReleaseWithData</option>";
echo "<option value=ReleaseWithUpdate>ReleaseWithUpdate</option>";
echo "</select>";
if($value=='Release'){
echo "Jack U r done";
}
?>
in above code if I select option as "Release", in the page echo message should be displayed.But it is not happeneing.
Can any body help me out how to resolve the issue.
Regards,
-Manoranjan
Re: Issue with PHP combo box select and d an action
Posted: Thu May 28, 2009 2:26 am
by papa
You need to use javascript for that. Or you can add a submit button and the variable passed is not $value, it's $_POST['jack'] or $_GET['jack'] depending on what you set your form to.
Re: Issue with PHP combo box select and d an action
Posted: Thu May 28, 2009 2:40 am
by mana_panigrahi
Hi,
Thanks for your reply.Could you please suggest how java script look like in this case.
Re: Issue with PHP combo box select and d an action
Posted: Thu May 28, 2009 2:51 am
by papa
<select name="jack" onchange="this.form.submit();">
Re: Issue with PHP combo box select and d an action
Posted: Thu May 28, 2009 2:54 am
by anand
Hi Manoranjan, See if this helps you or not.
Code: Select all
<?php
if($_REQUEST['jack']) {
$value = $_REQUEST['jack'];
if($value=='Release'){
echo "Jack U r done";
}
} else {
echo "<select name='jack' onchange='document.forms[0].submit();'>";
echo "<option value= Release>Release</option>";
echo "<option value=ReleaseWithData>ReleaseWithData</option>";
echo "<option value=ReleaseWithUpdate>ReleaseWithUpdate</option>";
echo "</select>";
}
?>
P.S. Why don't you use an Here Document?
Re: Issue with PHP combo box select and d an action
Posted: Thu May 28, 2009 4:12 am
by mana_panigrahi
Anand,
Thanks for your usggestion.I tried the same.but this is not working.
Can any body help me to create a combo box in PHP and selecting any option in combo list it should do certain action.
Re: Issue with PHP combo box select and d an action
Posted: Thu May 28, 2009 9:29 am
by anand
mana_panigrahi wrote:Anand,
Thanks for your usggestion.I tried the same.but this is not working.
Can any body help me to create a combo box in PHP and selecting any option in combo list it should do certain action.
Ok. I have tested this
Code: Select all
<?php
if($_REQUEST['jack']) {
$value = $_REQUEST['jack'];
if($value=='Release'){
echo "Jack U r done";
}
} else {
echo "<form method='post' action='xyz.php'>";
echo "<select name='jack' onchange='document.forms[0].submit();'>";
echo "<option value= Release>Choose One</option>";
echo "<option value= Release>Release</option>";
echo "<option value=ReleaseWithData>ReleaseWithData</option>";
echo "<option value=ReleaseWithUpdate>ReleaseWithUpdate</option>";
echo "</select></form>";
}
?>
It must work.
note that the default option must be either "Choose One" or "--------" and NOT a real option
Re: Issue with PHP combo box select and d an action
Posted: Fri May 29, 2009 12:22 am
by mana_panigrahi
Anand,
Thanks 4 your reply.It looks it is helpful to me.But one problem I am facing with this is I am trying to put the action(like echo or a text box or a combo box) besides the original combo box on same page once options are changed in the combo box.But the code you shared it is submitting to another page.
Kindly help me to put an input box atleast, besides the original combo box on same page.
Regards,
-Manoranjan
Re: Issue with PHP combo box select and d an action
Posted: Fri May 29, 2009 3:54 am
by achintha
here use this. I have modified & tested on localhost.Its working fine.
Code: Select all
<?php
if(isset($_REQUEST['jack']) && $_REQUEST['jack']=='Release' ) {
echo "Jack U r done";
}
else
{
echo "<form method='post' action='".$_SERVER['PHP_SELF']."'>";
echo "<select name='jack' onchange='document.forms[0].submit();'>";
echo "<option value= Release>Choose One</option>";
echo "<option value= Release>Release</option>";
echo "<option value=ReleaseWithData>ReleaseWithData</option>";
echo "<option value=ReleaseWithUpdate>ReleaseWithUpdate</option>";
echo "</select></form>";
}
?>
Re: Issue with PHP combo box select and d an action
Posted: Fri May 29, 2009 4:52 am
by mana_panigrahi
Anand,
Again thanks for your reply.
The code you sent shows the action(i.e. echo) that is done on same page when doing selection from combo box, but removes the old combo box on same page.
My requirement is that The old combo box should be there with the action(i.e. echo) next to combo box on same page when user select the different items from the combo box.
for example:if I select "Release" option then page should display Combo box holding the "Release" as option plus "Jack U r done"(action i.e. echo) besides the combo box.
Please suggest...
Regards,
-Manoranjna