|
-
Apr 3rd, 2004, 06:56 PM
#1
Thread Starter
Addicted Member
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
-
Apr 4th, 2004, 06:56 PM
#2
New Member
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.
-
Apr 6th, 2004, 12:08 PM
#3
Thread Starter
Addicted Member
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.
-
Apr 6th, 2004, 12:45 PM
#4
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...
-
Apr 6th, 2004, 12:49 PM
#5
Thread Starter
Addicted Member
is the proprty name unique to each option?
-
Apr 6th, 2004, 03:56 PM
#6
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?
-
Apr 6th, 2004, 04:01 PM
#7
Thread Starter
Addicted Member
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>
-
Apr 7th, 2004, 08:14 PM
#8
New Member
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.
-
Apr 9th, 2004, 09:07 AM
#9
Thread Starter
Addicted Member
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?
-
Apr 11th, 2004, 02:33 AM
#10
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:
varname = Request("monthname")
Select Case varname
Case "January"
varnumber = 1
Case "February"
varnumber = 2
'and so on
Whichever way you do it, you need to compare and assign.
-
Apr 12th, 2004, 10:26 AM
#11
Thread Starter
Addicted Member
But I don't want to hard code it. I want to bring it in from the recordset.
-
Apr 13th, 2004, 01:28 AM
#12
Then use <% =objrs.fields("fieldname").value %> when writing out the combo box.
-
Apr 13th, 2004, 07:47 AM
#13
Thread Starter
Addicted Member
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.
-
Apr 13th, 2004, 08:47 AM
#14
I just showed you how. You can work with your database fields instead of hardcoding it.
-
Apr 13th, 2004, 08:49 AM
#15
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|