Results 1 to 4 of 4

Thread: Populating a form field from a drop down

  1. #1
    Join Date
    Sep 2006
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Populating a form field from a drop down

    Hey guys,

    I'm trying to use one drop down menu - and select an item, once selected shows the cost up instantly in a form field nest to the drop down..

    There are maximum of 5 items, each with 5 different prices.

    i dont know if this is the right forum, but im writting in php, so thought id try here first

    Thanks for your help

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    This isn't php... it's javascript.
    The trick here is making the php output the right javascript code. Depending on the complexity of your php, and how much of the html it generates, it could be easy or hard. Hopefully, it's not too hard.

    Anyway, for the javascript code itself...

    <select onChange="result.value=this.value">
    <option value="1">One</option>
    <option value="2">Two</option>
    </select>
    <input type="text" id="result">

    Note: You might want to set an initial value in the textfield that matches the pre-selected option in the dropdown.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Sep 2006
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by djr33
    This isn't php... it's javascript.
    The trick here is making the php output the right javascript code. Depending on the complexity of your php, and how much of the html it generates, it could be easy or hard. Hopefully, it's not too hard.

    Anyway, for the javascript code itself...

    <select onChange="result.value=this.value">
    <option value="1">One</option>
    <option value="2">Two</option>
    </select>
    <input type="text" id="result">

    Note: You might want to set an initial value in the textfield that matches the pre-selected option in the dropdown.
    Hmmm ok, right, well its basically

    year one = 3.25
    year two = 6.50
    year three = 9.75

    and if i select year one i want to see 3.25 in a different readonly box next to the year selection...

  4. #4
    Join Date
    Sep 2006
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts

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
  •