By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,040 Members | 1,815 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,040 IT Pros & Developers. It's quick & easy.

combo box selected value problem

P: 17
I have a one combo box which display values from a table. But onchange i want the selected value in other text box.

[PHP]<?
echo "<select name='selectpg'>\n";
echo "<option value='Select Group' selected>Select Group</option>";
$query = "SELECT t.gname FROM group AS t ORDER BY t.gname ASC";
$res = @mysql_query($query);
while($row = mysql_fetch_array($res))
{
printf("<option value=\"$row[gname]\">$row[gname]</option>\n");
}
echo "</select>";
?>[/PHP]

Any body have idea about this, plz let me know

Thanks & Regards,
Praveen
Jan 9 '08 #1
Share this Question
Share on Google+
1 Reply


nathj
Expert 100+
P: 938
I have a one combo box which display values from a table. But onchange i want the selected value in other text box.

[PHP]<?
echo "<select name='selectpg'>\n";
echo "<option value='Select Group' selected>Select Group</option>";
$query = "SELECT t.gname FROM group AS t ORDER BY t.gname ASC";
$res = @mysql_query($query);
while($row = mysql_fetch_array($res))
{
printf("<option value=\"$row[gname]\">$row[gname]</option>\n");
}
echo "</select>";
?>[/PHP]

Any body have idea about this, plz let me know

Thanks & Regards,
Praveen
Hi Praveen,

I would do this with a simple javascript function called by the Select onchange event.

[html]
<select id="selectpg" onchcnage="poplateText('selectpg', 'textDisplay');"
[/html]
NOTE: 'textDisplay' is the ID of the input text you control where the value should display. the rest of your code should be fine, this is just to illustrate where the onchange call goes.

The javascript would look like:
[code]
function populateText(pcSourceID, pcTargetID)
{
// get the source value
lcSourceValue = document.getElementById(pcSourceID).value ;
//set the target value
document.getElementById(pcTargetID).value = lcSourceValue ;
}

This simple function should do the trick.

Cheers
nathj
Jan 10 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.