|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
||||
|
||||
|
getting text from option boxes
ok i need to get the text from an option box? i know you can do it with java script but it would make my life a lot easier if you can get it using asp. don't know if there is a method out there or what. any ideas?
__________________
My brain cells are like a storm trooper's armor: useless |
|
#2
|
|||
|
|||
|
What's an option box ?
Do you mean like a checkbox or a radio button ? Either way, simply add a value attribute to the control of choice(checkbox or a radio button) Then retrieve it like the usual! <% Dim strValue strValue = Request.Form("...") 'OR strValue = Request.QueryString("...") %> Hope this helps! Sincerely Vlince |
|
#3
|
||||
|
||||
|
sorry should have been more specific.
<select> <option value="<%databaserecordnumber%>"><%dbtext%> </option> </select> i need the value to stay as the number so i can run other queries. i need the <%dbtext%> on form submit |
|
#4
|
|||
|
|||
|
If you assign a value, the name is not passed in the post, bummer huh?
my workaround is to instead of submitting to another page to have it be a button and onclick call javascript to open a new page and pass in variables in querystring to that do whatever, and if it needs to pass values back you can call any function from the parent page with window.opener.function_name() in the child window. I just found out about this last week so I'm still experimenting with it, but it works great from what i've seen. I can post some example when i go to work today if you need them.... |
|
#5
|
|||
|
|||
|
Many ways to do that!
I personaly prefer having both values inside the value attribute of the <option> tag seperated by a delimiter For example: <select> <option value="<%databaserecordnumber%>;<%dbtext%>"><%dbtext%> </option> </select> Notice the --> ; <-- between <%databaserecordnumber%> and <%dbtext%>? Now when you submit your <form>...</form>(Yes, I assumed you had a <form>...</form>) Then you simply retrieve the value of your <select>...</select> like this: <% Dim strSelectValues Dim strSelectedText 'Notice the variable name strSelectValues its a plural name 'why? because it will hold the combination of : '<%databaserecordnumber%> and <%dbtext%> seperated by a 'semicolon remember? So its gonna hold two values. 'Since the value YOU want is the second one(<%dbtext%>) 'what you do next is trivial...look! strSelectValues = Trim(Request.Form("slc")) 'FOR DEBUG ONLY 'Response.Write "-->" & strSelectValues & "<--<hr>" 'Response.End strSelectedText = Split(strSelectValues, ";")(1) 'FOR DEBUG ONLY 'Response.Write "-->" & strSelectedText & "<--<hr>" 'Response.End %> I've assumed, once again, that the name of your <select>...</select> was slc hence the : Request.Form("slc") I've also assumed your <form>...</form> was using the method POST hence the Request.Form Now the tricky part, Split() returns an array but if you specify the element you want/need like in the above example: Split(strSelectValues, ";")(1) Notice the (1) it will return that element. So your variable strSelectedText is NOT an array but a STRING hence the str prefix! Arrays begin at 0 I wanted the second element in the array, I wanted the (1) which represents <%dbtext%> Hope this helps! Sincerely Vlince |
|
#6
|
|||
|
|||
|
I don't think you'll need to write that book vlince, i think you've already written it. Just copy and past devshed excerpts you've written. My response would have just been to add the ; in and do a split, but you go all out and leave nothing to the imagination.
tell me when the book finally gets published, I'll want a signed copy haha. |
|
#7
|
|||
|
|||
|
Hehe
![]() Nah...no books coming out although I'd like to but it might be in French since it's my native language Not only that, but how can *I* compete with Jessy Liberty from O'reilly I mean c'mon ![]() This guy's amazing! Can we write articles here at devshed? Do they pay for that? |
|
#8
|
|||
|
|||
|
haha, if you ask them they'll say they pay you in satisfaction in knowing you helped someone out today
kinda like the, "mom, we have mom's day but when is kids' day?" and she replies "why, everyday is kids day honey" |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > getting text from option boxes |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|