Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to code pull-down menu in vbs & asp 1

Status
Not open for further replies.

jfdabiri

MIS
Feb 27, 2007
282
US
hi,
i have this asp that has this code:
Code:
<form name=frm2>
     <SELECT NAME="sortby" SIZE="1"> 
     <OPTION>Select Sort Option</option>       
     <OPTION>Sort By Name</option>
     <OPTION>Sort By Housing Unit</option>                  
     </SELECT>
</form>
which is a pull-down menu (list box).
when i try to access the selected item, i get an error. here's the code i'm using for getting the selected option:
Code:
sort_option = document.frm2.sortby.options _
                 (frm2.sortby.options.selectedindex).text

thanks.
 
Typed, untested:
sort_option = document.frm2.sortby.options _
([!]document.[/!]frm2.sortby.options.selectedindex).text

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
thanks, phv.
i'm getting this error:
Microsoft VBScript runtime error '800a01a8'
Object required: ''
/custom_apps/testing.asp, line 29
which is this line:
sort_option = document.frm2.sortby.options _
(document.frm2.sortby.options.selectedindex).text

 
[1] If those lines occurred on client-side, there shouldn't be error of the sort. It is not scripted in the form I subjectively like to see, but html on ie would accommodate it.

[2] The problem is probably something related to client-side handler calling some server-side variable or object.

[3] The only thing I would suggest you must do is to script the value attribute to the options. Server=side only see the posted data of the select-one element only the ".value". ".Text" won't be sent to the server on ie. (moz/ff however will automatically established value equal to the text and post to the server.)
[tt]
<form name=frm2>
<SELECT NAME="sortby" SIZE="1">
<OPTION value="Select Sort Option">Select Sort Option</option>
<OPTION value="Sort By Name">Sort By Name</option>
<OPTION value="Sort By Housing Unit">Sort By Housing Unit</option>
</SELECT>
</form>
[/tt]
 
thanks tsuji.
how would the code look like? how would i retrieve the user's selection?
 
[4] Here like this.
[tt]<html>
<head>
<script language="vbscript">
sub doit
dim sort_option
sort_option = document.frm2.sortby.options _
(frm2.sortby.options.selectedindex).text
alert(sort_option)
end sub
</script>
</head>
<body>
<form name=frm2 method="post" action="xyz.asp">
<!-- <SELECT NAME="sortby" SIZE="1"> -->
<SELECT NAME="sortby" SIZE="1" onchange="doit">
<OPTION>Select Sort Option</option>
<OPTION>Sort By Name</option>
<OPTION>Sort By Housing Unit</option>
</SELECT>
<input type="submit" />
</form>
</body>
</html>
[/tt]
I use your script as much as possible. (I prefer to attach document to frm2 as PHV suggested. I would quote all the attribute. I would not have case in chaos.... etc)

[5] Client-side the alert shows you the result.

[6] Server-side (xyz.asp), you can get the value (which may be scripted differently from the .text, there is no such restriction .value must equal to .text. .value is set to value so that the server action script understood the choice.)
[tt]
<%
'xyz.asp
'I use the same name just to confuse you and make you think
'now it is a server-side variable different animal from the client-side
dim sort_option
sort_option=request.form("sortby)
response.write sort_option & "<br />" 'demo for verification
%>
[/tt]
 
amendment
The corresponding line should be read, as a matter of course.
[tt]sort_option=request.form("sortby[red]"[/red])[/tt]
 
tsuji,
thanks. i think i'm on the right track here. basically, i have 2 .asp's
1 - (testing3.asp) presents the options:
a - sort by name or living unit
b - building_location
2 - (testing4.asp) actually does the db call to oracle table.
my question is that how do i retrieve selected options that they selected in testing3, in testing 4? or, in other words, how are these variables passed between the two pages?
thanks.
 
i got one item (sort option) to be passed to the 2nd asp. but, the 2nd option (building id) is not being passed. is there anyway to pass both of these items to the 2nd asp?
thanks.
 
As long as the two drop-down lists (select-one element) are in the same form (named frm2) being submitted, you can retrieve the selected ones the same way. Suppose the building_location drop down list is named "building_location", on the test4.asp it is retrievd the same way as sortby.
[tt]
<%
dim sort_option, location_option
sort_option=request.form("sortby")
location_option=request.form("building_location")
'etc etc
%>
[/tt]
ps I hope you've rediscoved the necessity of scripting the value attribute in the option tags. (I left out in [4] what mentioned in [3])
 
tsuji,
thanks so much. i got it working perfectly based on the advice you gave. basically i found that the first asp page passes the data to the called asp, and the called asp, retrieves the data using:
sort_option=request.form("sortby") and
building_location = request.form("builiding_location")

i now have a better understanding of the pheonms
thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top