Results 1 to 6 of 6

Thread: passing a value to a pulldown menu in ASP

  1. #1

    Thread Starter
    Hyperactive Member vbuser1976's Avatar
    Join Date
    Sep 2000
    Location
    Yonkers, NY
    Posts
    404

    Cool

    Greetings to all my forum buddies!

    I know this is a newbie question, but I don't know how to do this in vbscript.

    I have a pulldown menu in an edit form. The form calls a recordset and puts the records in their corresponding boxes. I want the pulldown menu, when passed the value, to default to that value. How do I do that with out losing the options in the pull down.

    I hope this doesn't sound confusing. Thanks in advance.
    -vbuser1976
    VB6 Enterprise SP6
    SQL 7.0 SP2
    VBScript, HTML, Javascript, C++, a little UNIX

  2. #2
    Lively Member chrisgaddy's Avatar
    Join Date
    Mar 2001
    Location
    Olive Branch, MS
    Posts
    71
    Are the values in your pulldown box coming from a recordset also? Basically, you want to make the value from the recordset selected. Like this:

    <option value="1" selected>Option 1</option>

  3. #3
    Addicted Member Active's Avatar
    Join Date
    Jan 2001
    Location
    Lat: 13° 4' 46" N, Long: 80° 15' 20" E
    Posts
    209
    See this If it helps....

    <%
    Dim Rating(3),RatingID

    '.... Database code ......
    'RatingID has a value from the database
    'Say the Possible values are 0,1,2,3
    '.........................

    Rating(RatingID)= "Selected "

    %>

    <form>
    <select name=Ratings>
    <option value=0 <%=Rating(0)%>>Poor</option>
    <option value=1 <%=Rating(1)%>>Fair</option>
    <option value=2 <%=Rating(2)%>>Good</option>
    <option value=3 <%=Rating(3)%>>Excellent</option>
    </Select>
    </form>
    If you can't beat your computer at chess, try kickboxing !!!
    [Download Tag Editing Tools.]

  4. #4

    Thread Starter
    Hyperactive Member vbuser1976's Avatar
    Join Date
    Sep 2000
    Location
    Yonkers, NY
    Posts
    404

    Smile Yes!

    Originally posted by chrisgaddy
    Are the values in your pulldown box coming from a recordset also? Basically, you want to make the value from the recordset selected. Like this:

    <option value="1" selected>Option 1</option>
    The values of the pull-down box are not coming from the recordset, but what you said is basically what I want to do. Lemme explain: the pulldown box has selections of 5 values(1 to 5). When they select one and save, a copy of the selected value goes to the recordset. When they want to edit that recordset, I want the value that is being returned to become the default selected. Then, if they need to, they can change it. Therefore, from what you said above, yes I want to make the value from the recordset selected.

    Thanks chrisgaddy and Active for all your input.
    -vbuser1976
    VB6 Enterprise SP6
    SQL 7.0 SP2
    VBScript, HTML, Javascript, C++, a little UNIX

  5. #5
    Lively Member chrisgaddy's Avatar
    Join Date
    Mar 2001
    Location
    Olive Branch, MS
    Posts
    71
    Ok, there's probably 50 ways to do this, and I don't think there's a right or wrong way. There may be a faster way(my favorite), but here's one way:

    rs.Open "SELECT * FROM sometable",con,....

    Select Case rs("fieldValue")
    Case 1
    strOptions = "<option value='1' selected>Option1 </option>"
    strOptions = strOptions & "<option value='2'>Option 2</option>"

    Case 2
    strOptions = "<option value='1'>Option 1</option>"
    strOptions = strOptions & "<option value='2' selected>Option 2</option>"

    and so on and so on....

    Now in your html code it should look like this:

    <select name="someName"><%=strOptions%></select>

    Hope that helps.

  6. #6

    Thread Starter
    Hyperactive Member vbuser1976's Avatar
    Join Date
    Sep 2000
    Location
    Yonkers, NY
    Posts
    404

    Talking Thanks

    That was what I was looking for.

    Enjoy your weekend!
    -vbuser1976
    VB6 Enterprise SP6
    SQL 7.0 SP2
    VBScript, HTML, Javascript, C++, a little UNIX

Posting Permissions

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



Click Here to Expand Forum to Full Width