Page 1 of 2 12 LastLast
Results 1 to 10 of 14

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,

    Ok, i put this in php by mistake...

    can anyone help please?

    Quote Originally Posted by My First Post
    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

    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.

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

    Default

    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...

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

    Default

    Well, just change the values. Simple as that.

    If you wanted to do math, you can do that in JS as well.


    As for readonly... I'm not sure what the code is for that.

    I just tried:
    <input type="text" id="result" readonly>
    And that worked, though I'm not sure if that's the "official" way to do it. Easy, though
    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

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

    Default

    Quote Originally Posted by djr33
    Well, just change the values. Simple as that.

    If you wanted to do math, you can do that in JS as well.


    As for readonly... I'm not sure what the code is for that.

    I just tried:
    <input type="text" id="result" readonly>
    And that worked, though I'm not sure if that's the "official" way to do it. Easy, though
    Oh ok, so do i not need any code..
    sorry for the stupid questions but i dont know javascript very well at all..

    What i need is

    the user selects eg. 1 year - 3.25
    then in a second drop down selects : item 1 - 25.00

    then i want a field that adds Drop down one + drop down two,
    and displays the result - 28.25

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

    Default

    hmm, ok, yeah just sorted that, thank you

    PHP Code:
    if ( $item == "item1, item2" ){ 
    i tried
    PHP Code:
    if ( $item == "item1""item2" ){ 
    and
    PHP Code:
    if ( $item == "item1" OR "item2" ){ 
    now, this doesnt work, what i want is if item is item1 or item2 then do this:
    xxxx

  6. #6
    Join Date
    Sep 2005
    Posts
    882
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    PHP Code:
    if($item == 'item1' || $item == 'item2'){
    //Do stuff here


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

    Default

    Do you mean to be using php now?
    Or is this still a javascript operation?
    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

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

    Default

    excellent, all working now thank you!

    now im having a problem passing info via a mail.php

    i have an ordering page, --> mail.php --> payment page.

    the info goes to the mail.php page but not to the payment page.. can anyone help?

  9. #9
    Join Date
    Sep 2005
    Posts
    882
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    You can probably rig up a redirect, or some hidden fields(remeber to revalidate), but first I need to know what variable you want sent to mail.php

  10. #10
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by djr33
    As for readonly... I'm not sure what the code is for that.

    I just tried:
    <input type="text" id="result" readonly>
    And that worked, though I'm not sure if that's the "official" way to do it. Easy, though
    Why didn't you look at the HTML specification? Read-only controls

    Mike

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
  •