Hi-
I am creating a basic form that posts data to a mySQL database. One of my tables, called "sites", contains the following information: site_name, site_id. I have created a dynamic dropdown menu of the sites (so the dropdown menu references the table "sites" to display all site names in a dropdown list). Based on the site_name selection, I would like the site_id to automatically populate the next text box in my form. **Here's the catch. I do not want to use any java or ajax. ** Please excuse the messy code, I deleted a lot of the private information. Thank you for your help in advance.

<html>

<form action="mait.php" method="post">

Site Name:  
      <?php

        mysql_connect("localhost", "root", "") or die(mysql_error());
        mysql_select_db("database1") or die(mysql_error());


        $sql = "SELECT site_name FROM sites ORDER BY site_name";

        echo "<SELECT name='mait_site'>";

        $result = mysql_query($sql);

        while ($row = mysql_fetch_assoc($result)) {

        echo '<option value="'.$row["site_name"].'">'
        .$row["site_name"].'</option>';
        }

        echo "</SELECT>";
        ?>

Site ID:
    <<<<<neeed this field automatically populated based on Site Name selection>>>>>

</form>
</html>
Member Avatar for iamthwee

If you don't want to use ajax then as you select an option and then form submit it will have to go to another page or something like that.

I would say opting to NOT use jquery is a daft idea as every browser should have it enabled and it is dead simple vis a vis:

http://jsfiddle.net/GWact/

Thanks for the response. As long as jquery is a universal function, I will give it a shot. I see that your example is simply pulling the fill in options from the code. Does jquery have the ability to grab that supplemental information from a MySQL table?

Member Avatar for iamthwee

Yes

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.