开发者

populate text filed based on a dynamic dropdown list

开发者 https://www.devze.com 2023-03-19 09:42 出处:网络
I have a table that contains: -First Name -Last Name -Address -City -etc What i what to do is :from a drop down list that displays the First Name and Last Name, when i select a Name to automatically p

I have a table that contains: -First Name -Last Name -Address -City -etc What i what to do is :from a drop down list that displays the First Name and Last Name, when i select a Name to automatically populate a text area with the other fields :Adress, City, etc. It display the names in the drop down list but nothing in the text after selecting a name. I would really need some help. This is the code till now:

  $dbu = new ps_DB;
$quer="SELECT * FROM #__ckforms_1";
$dbu->query($quer);
echo '<div style="float:right; margin-top: 50px;">';
    echo "<select name='client' style='width:150'  onchange='updateText();' ><option value=''></option>";
        while($dbu->next_record()) { 
            $id = $dbu->f("id");
            $first=$dbu->f("F1");
            $last = $dbu->f("F2");
            $adress= $dbu->f("F3");
            $city=$dbu->f("F4");
            echo "<option value='$id'>$first   $last </option>"."<BR>";

        }
        echo "</select>";
        echo "<BR>"; 
    echo "<input type='text' name='F3' id='F3' readonly='readonly' >";
    echo "<input type='text' name='F4' id='F4' readonly='readonly' >";

and the javascript

function updateText()
    {
    var dd = document.getElementById('id');
    var ddtext = dd.options[dd.selectedIndex].text;
    var sp_ddtext = ddtext.replace(/(\w+)\s\s+/g,''); 
    document.getElementById('F3').value = sp_ddtext;
    document.getElementById('F4').value 开发者_C百科= sp_ddtext;
    }

Thank you in advance!


I solved this with PHP - AJAX and MySQL

0

精彩评论

暂无评论...
验证码 换一张
取 消