Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Fill text fields by selecting listbox value (Mysql)

    Hello!
    I'm not very confortable with javascript and need some help.
    I have the following scipt on my php page:

    PHP Code:
    <?php 

    $resultado
    =mysql_query("select * FROM associated  ORDER BY enterprise asc") or die("Erro ao listar tabela"); 
        echo (
    "<table width=\"95%\" border=\"0\">"); 
        echo 
    "<tr>"
        echo 
    "<td class=\"texto\"><form name=\"associated\" method=\"post\" action=\"\" ><select name=\"list\"> <option value=\"\" selected>Associated List</option>"
        while (
    $registo=mysql_fetch_row($resultado)) 
        { 
            echo 
    "<option value=\"$registo[1]\">$registo[1]</option>"
        } 
        echo 
    "</select><br>"
        echo 
    "<input type=\"text\" name=\"adress_field\"><br>"
        echo 
    "<input type=\"text\" name=\"sector_field\"><br>"
        echo 
    "<input type=\"submit\" name=\"Submit2\" value=\"Submit\">"
        echo 
    "</form></td>"
        echo 
    "</tr>"
        echo (
    "</table>"); 
         
        
    mysql_close(); 
         
    ?>
    Well, I know this is a javascript forum but what I need is a javascript.
    As you may see, the listbox has dynamic content from a Mysql table with the "id, enterprise, adress, sector" fields.
    I now wanted to chose an enterprise from the list box and the two text fields below would be automatic filled with the correspondent data from the mysql table.
    Hope this is understandable...
    Thanks in advance!
    Last edited by fana605; 02-03-2005 at 02:16 PM. Reason: title changing

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Unfortunetely you did not provide the necassary information as to how the data coming from the database is displayed in the option values... But assuming the it is comma delimited and the address is first while the sector is second, the solution would be something like so...

    Code:
    echo "<td class=\"texto\"><form name=\"associated\" method=\"post\" action=\"\" >
    <select name=\"list\" onchange="this.form.adress_field.value='this.value.split(',')[0];this.form.sector_field.value='this.value.split(',')[1]">
    <option value=\"\" selected>Associated List</option>";
    .....Willy


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •