combo box selected value problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • praveenkrg
    New Member
    • Sep 2007
    • 17

    #1

    combo box selected value problem

    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($q uery);
    while($row = mysql_fetch_arr ay($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
  • nathj
    Recognized Expert Contributor
    • May 2007
    • 937

    #2
    Originally posted by praveenkrg
    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($q uery);
    while($row = mysql_fetch_arr ay($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="popl ateText('select pg', '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(pc SourceID, pcTargetID)
    {
    // get the source value
    lcSourceValue = document.getEle mentById(pcSour ceID).value ;
    //set the target value
    document.getEle mentById(pcTarg etID).value = lcSourceValue ;
    }

    This simple function should do the trick.

    Cheers
    nathj

    Comment

    Working...