Results 1 to 15 of 15

Thread: Option Id tag

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2004
    Posts
    182

    Option Id tag

    Question:

    I set the option id to a value but when I reference it it is null. What am I doing wrong?
    <SELECT size=1 name=cboDiv style="WIDTH: 105px" >
    Response.Write "<option id=" & Type1 & " value="& Type2 &">"& Type1 &"</option>"
    </select>


    msgbox document.addproj.cbodiv.id

  2. #2
    New Member
    Join Date
    Mar 2004
    Location
    Sydney, Australia
    Posts
    6
    You don't reference options as objects. You need to assign an id to the SELECT tag, and reference it, manipulating it's value as necessary.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2004
    Posts
    182
    but isn't the id a property of the option tag?? if I set the id of the select tag then I can't capture which option was selected.

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    No, it should be like this:

    Code:
    <select id="propertyname">
    <option value="one">1</option>
    <option value="two">2</option>
    ...
    Now, you get it by requesting the "propertyname" variable, which would have a value of "one", "two" or whatever...

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Mar 2004
    Posts
    182
    is the proprty name unique to each option?

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Let me give you a better example:

    <select id="month">
    <option value="january">1</option>
    <option value="february">2</option>
    <option value="march">3</option>
    <option value="april">4</option>



    Now, retrieving the value for "month" in the next page would give you january, february, march, or april... etc...

    So you define the "variable name" in the select tag, and the possible values in the option tags.

    Comprende senor?

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Mar 2004
    Posts
    182
    Ok, Depending on the situation I want to reference the January or the 1. So I was going to do the following code but that is wrong. So How do I reference the 1???

    <option id="1" value="january">1</option>

  8. #8
    New Member
    Join Date
    Mar 2004
    Location
    Sydney, Australia
    Posts
    6
    You can't. You can only reference the value property itself (in this case, "january"). There's no reason why you couldn't write an array/collection to match month names with the corresponding integer, or any value for that matter.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Mar 2004
    Posts
    182

    Wink

    Ok so my array is like this.
    array(0,1) ="January"
    array(1,1)="01"

    So if they select "01" from the combo box how do I reference January?

  10. #10
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Realgoldn,

    You know you could just switch the things around:

    <select id="month">
    <option value="1">January</option>
    <option value="2">February</option>
    ...



    Anyways, if we go by your question:

    Ok so my array is like this.
    array(0,1) ="January"
    array(1,1)="01"

    So if they select "01" from the combo box how do I reference January?
    If they select 1 from the original list I showed you, then you'd get January automatically when you Request it on the next page. What you can do is to compare the value being retrieved


    VB Code:
    1. varname = Request("monthname")
    2.  
    3.  
    4. Select Case varname
    5. Case "January"
    6. varnumber = 1
    7.  
    8. Case "February"
    9. varnumber = 2
    10.  
    11. 'and so on

    Whichever way you do it, you need to compare and assign.

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Mar 2004
    Posts
    182
    But I don't want to hard code it. I want to bring it in from the recordset.

  12. #12
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Then use <% =objrs.fields("fieldname").value %> when writing out the combo box.

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Mar 2004
    Posts
    182
    I don't want to hardcode the varname=1 I want to get those values from my table so incase the table changes I won't have to alter the code on the page.

  14. #14
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    I just showed you how. You can work with your database fields instead of hardcoding it.

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Mar 2004
    Posts
    182

    Talking

    Ok, Thanks-

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