Hello and welcome to our community! Is this your first visit?
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
    Thanked 0 Times in 0 Posts

    Smile Fill text fields by selecting listbox value (Mysql)

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

    PHP Code:

    =mysql_query("select * FROM associated  ORDER BY enterprise asc") or die("Erro ao listar tabela"); 
        echo (
    "<table width=\"95%\" border=\"0\">"); 
    "<td class=\"texto\"><form name=\"associated\" method=\"post\" action=\"\" ><select name=\"list\"> <option value=\"\" selected>Associated List</option>"
        while (
    "<option value=\"$registo[1]\">$registo[1]</option>"
    "<input type=\"text\" name=\"adress_field\"><br>"
    "<input type=\"text\" name=\"sector_field\"><br>"
    "<input type=\"submit\" name=\"Submit2\" value=\"Submit\">"
        echo (
    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
    Join Date
    Sep 2003
    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...

    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>";


    Posting Permissions

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