Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

how can I read combobox selected value

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

how can I read combobox selected value

Postby stephenrodrics » Thu Mar 14, 2013 6:15 am

I am new to php i want to display a text based on the item selected in combo box, how can i do so please expain

i am using the below code but nothing is happening


<html>
<body>
Department:
<p>
<select name="dep" onChange='window.location.href="tu.php?dep="+this.value;'>
<option value="" selected>--</option>
<option value="it">IT</option>
<option value="f">Finance</option>
<option value="s">Sales</option>
</select>
</p>
</body>
</html>
<?php
$dep=@$_GET["dep"];
switch($dep)
{
case 'it':
echo "Software Developer, Graphic Designer, Web Designer, Technical Support";
alert("test");
break;
case 'f':
echo "Cost Analyst, Chartered Accountant, Company Secretary Accountant, Auditor";
break;
case 's':
echo "Sales Executive, Sales Manager, Sales Analyst";
break;
default:
echo "";
}
?>
stephenrodrics
New php-forum User
New php-forum User
 
Posts: 58
Joined: Thu Mar 14, 2013 6:10 am

Re: how can I read combobox selected value

Postby johnj » Thu Mar 14, 2013 8:18 pm

Use onchange() method of JavaScript or the change function in jquery to display whatever text you want
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: how can I read combobox selected value

Postby stephenrodrics » Thu Mar 14, 2013 10:52 pm

johnj thanks for the prompt reply.

is there any book of website or sample which i can refer to to understand php controls specially combobox
stephenrodrics
New php-forum User
New php-forum User
 
Posts: 58
Joined: Thu Mar 14, 2013 6:10 am

Re: how can I read combobox selected value

Postby johnj » Fri Mar 15, 2013 2:33 am

johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: how can I read combobox selected value

Postby seandisanti » Fri Mar 15, 2013 8:01 am

w3schools.com is a great resource also, and it's actually html controls rather than php
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm


Return to PHP coding => General

Who is online

Users browsing this forum: Google Feedfetcher and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.