SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    May 2004
    Location
    new york
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Auto fill form fields with mysql data for selected pull down option

    I have some form fields that the user can either type in or he can check a checkbox so that MySQL data for an option selected from a dynamically generated (PHP/MySQL) select menu is filled in. How can this be implemented? I have the code for the select menu. Thank you.

  2. #2
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is the page online so we can take a look?

  3. #3
    SitePoint Member
    Join Date
    May 2004
    Location
    new york
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It is not online. But I have something like this script to fill in day/date fields in forms.

  4. #4
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's the basic idea...
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <style type='text/css'>
    </style>
    <script type='text/javascript'>
    
    window.onload = winOnLoad;
    
    function winOnLoad()
    {
      if (!document.getElementById) return;
      document.getElementById('chk1').onclick = chkOnClick;
      document.getElementById('sel1').onchange = selOnChange;
    }
    function chkOnClick()
    {
      var txt = document.getElementById('txt1');
      if (this.checked) {
        var sel = document.getElementById('sel1');
        txt.value = sel.options[sel.selectedIndex].text;
        txt.disabled = true;
      }
      else {
        txt.disabled = false;
      }
    }
    function selOnChange()
    {
      if (document.getElementById('chk1').checked) {
        document.getElementById('txt1').value = this.options[this.selectedIndex].text;
      }
    }
    </script>
    </head>
    <body>
    
    <form>
    
    <input id='txt1' type='text'>
    <input id='chk1' type='checkbox'>
    
    <select id='sel1'>
      <optgroup label='Breakfast'>
        <option>Eggs</option>
        <option>Bagels</option>
        <option>Cereal</option>
      </optgroup>
      <optgroup label='Lunch'>
        <option>Soup</option>
        <option>Fruit</option>
        <option>Salad</option>
        <option>Sandwich</option>
      </optgroup>
      <optgroup label='Dinner'>
        <option>Fish</option>
        <option>Pork</option>
        <option>Steak</option>
        <option>Chicken</option>
        <option>Vegetables</option>
      </optgroup>
    </select>
    
    </form>
    
    </body>
    </html>


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
  •