Issue with PHP combo box select and d an action

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
mana_panigrahi
Forum Newbie
Posts: 10
Joined: Fri May 08, 2009 8:22 am

Issue with PHP combo box select and d an action

Post 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
Last edited by Benjamin on Fri May 29, 2009 10:32 am, edited 1 time in total.
Reason: Changed code type from text to php.
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Issue with PHP combo box select and d an action

Post 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.
mana_panigrahi
Forum Newbie
Posts: 10
Joined: Fri May 08, 2009 8:22 am

Re: Issue with PHP combo box select and d an action

Post by mana_panigrahi »

Hi,
Thanks for your reply.Could you please suggest how java script look like in this case.
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Issue with PHP combo box select and d an action

Post by papa »

<select name="jack" onchange="this.form.submit();">
anand
Forum Commoner
Posts: 80
Joined: Fri May 22, 2009 11:07 am
Location: India
Contact:

Re: Issue with PHP combo box select and d an action

Post 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?
mana_panigrahi
Forum Newbie
Posts: 10
Joined: Fri May 08, 2009 8:22 am

Re: Issue with PHP combo box select and d an action

Post 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.
anand
Forum Commoner
Posts: 80
Joined: Fri May 22, 2009 11:07 am
Location: India
Contact:

Re: Issue with PHP combo box select and d an action

Post 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
mana_panigrahi
Forum Newbie
Posts: 10
Joined: Fri May 08, 2009 8:22 am

Re: Issue with PHP combo box select and d an action

Post 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
achintha
Forum Newbie
Posts: 13
Joined: Mon Apr 30, 2007 10:21 am

Re: Issue with PHP combo box select and d an action

Post 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>";
}
?>
Last edited by Benjamin on Fri May 29, 2009 10:32 am, edited 1 time in total.
Reason: Changed code type from text to php.
mana_panigrahi
Forum Newbie
Posts: 10
Joined: Fri May 08, 2009 8:22 am

Re: Issue with PHP combo box select and d an action

Post 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
Post Reply