Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Oct 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    populate txtfield using record ID from value of select box

    Hi, I'm using ASP to pull in a recordset and populate a select box.:

    my table for the recordset looks like this:

    OptionId OptionName OPtionPrice

    the Select box is populated as follows:

    value = optionID, title = OPtionName

    When the user selects an OptionName, I need to somehow, re-query the recordset (or by whatever other means you guys suggest) and find the correct price.. Then I shove that price into the textfield.

    One 'hack' would be to simply have the optionprice as the value of the list boxes and push that into the txtfield on change.. but that's no good as when the form is submitted, I need that OPtionId value to do some other stuff.

    I know ASP back to front, but Javascript?? I'm pretty bad.

    Can anyone point me in the right direction?

    Thanks

    James

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Actually you need two value fields, one to hold the optionID and one to hold the OptionPrice. The nice thing is that you can use the one field provided as if it were two separate fields by using a delimiter character (pick a character that won't be in the text of either field). Then when an option is picked and you get the value of the option you can then use the javascript split function to make that value into it's discrete parts, displaying the price.

    When the form is submitted you can parse the submitted value to extract just the optionID part.
    Check out the Forum Search. It's the short path to getting great results from this forum.

  • #3
    New to the CF scene
    Join Date
    Oct 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    excellent!

    bever thought of that

    however I am struggling a little with the split function for javascript.

    I know how it works in ASP, but not sure of my code for javascript:
    here's my simple code for now.

    onchange="formName.fieldName.value=formName.selectListName[formName.selectLi
    stName.selectedIndex].value;"


    James

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Assuming you use "~" as your separator character and the price is the first field then you'd do something like:

    Code:
    onchange="var ss,sa; ss=formName.selectListName[formName.selectLi
    stName.selectedIndex].value; sa=ss.split('~'); formName.fieldName.value=sa[0];return true;"
    Check out the Forum Search. It's the short path to getting great results from this forum.


  •  

    Posting Permissions

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