How to populate a text box with data....

Discussion in 'PHP' started by karfeef, May 9, 2007.

  1. #1
    Hi all. new member and fairly new to php/mysql. i wonder if someone can help.

    i am trying to create a simple form, with a single drop down list, populated from column 1 of a mysql table. what i need to happen is when an item is selected from the list, the text box underneath populates with the data from the same row in column 2 of the table, then the value of the textbox is posted to another table (but i already have that bit as i'm modifying an existing form) i just can't figure it :eek:

    it can happen either from the selection event or by using a button

    can anyone help? many thanks

    Karf
     
    karfeef, May 9, 2007 IP
  2. NoamBarz

    NoamBarz Active Member

    Messages:
    242
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #2
    You'd have to either repload the page or use ajax. The event you are looking for is: <select name='whatever' onchange='captureEvent()'>

    To learn more about ajax, try this url: http://www.mousewhisperer.co.uk/ajax_page.html

    If, on the other hand you want to reload the page, you'd have to select the data from your table using a select statement.

    Ajax is very common today.
     
    NoamBarz, May 9, 2007 IP
  3. lemaitre

    lemaitre Peon

    Messages:
    61
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    This is not hard at all. In your PHP script, use the result set from the database query to write a Javascript associative array which maps the values from column 1 to values in column 2. Write the dropdown values as usual. Then go to the Javscript forum and ask for help writing a function that fills in the text box from column 2 of the array.
     
    lemaitre, May 9, 2007 IP
  4. gibex

    gibex Active Member

    Messages:
    1,060
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    95
    #4
    gibex, May 10, 2007 IP
  5. karfeef

    karfeef Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thank you all. looks like i need to crack on with some reading =)
     
    karfeef, May 11, 2007 IP