SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Sep 2003
    Location
    Temecula, CA
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Dynamic Option Lists

    I have found several codes to dynamically change the second & third pulldowns.

    My questions is: Can JS conect to a database to pull the info from?
    Code:
    //The JavaScript code looks like this:
    
    function UpdateSample1()
    {
      var makeSelect = document.forms.sample1.make;
      var modelSelect = document.forms.sample1.model;
    
      modelSelect.options.length = 0; // Clear the popup
    
      if (makeSelect.options[makeSelect.selectedIndex].value == "Ford")
      {
        modelSelect.options[0] = new Option("Explorer");
        modelSelect.options[1] = new Option("Mustang");
        modelSelect.options[2] = new Option("Probe");
      }
      else if (makeSelect.options[makeSelect.selectedIndex].value == "Toyota")
      {
        modelSelect.options[0] = new Option("Camry");
        modelSelect.options[1] = new Option("Celica");
        modelSelect.options[2] = new Option("MR2");
        modelSelect.options[3] = new Option("4Runner");
      }
    } 
    
    //The HTML source looks like this:
    
    <form name="sample1">
      <select size="1" name="make" onchange="UpdateSample1()">
        <option value="Ford" selected>Ford</option>
        <option value="Toyota">Toyota</option>
     </select>
     <select size="1" name="model">
        <option selected>Explorer</option>
        <option>Mustang</option>
        <option>Probe</option>
      </select>
    </form>
    Found at http://javascript.about.com/library/.../aa072903a.htm
    So instead of having to add a new model in this code, when I add it into the database it would pull from there -- to populate the second pull down.

    Thanks

  2. #2
    SitePoint Enthusiast yjgx007's Avatar
    Join Date
    Jul 2004
    Location
    China or Singapore?
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you can using ASP or PHP etc. with Javascript.

  3. #3
    SitePoint Zealot
    Join Date
    Sep 2003
    Location
    Temecula, CA
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, I'm learning PHP, so would the php go into the JS?

    Thank you fo ryour quick reply. I guess I got my work cut out for me.

    Thanks


Bookmarks

Posting Permissions

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