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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

asp/vbs - select/option problem

Status
Not open for further replies.

jfdabiri

MIS
Feb 27, 2007
282
US
i have this code:
<SELECT NAME="quarter" SIZE="1">
<OPTION>Select a Quarter</option>
<OPTION>2005-Q1</option>
<OPTION>2005-Q2</option>
</SELECT>

I'm trying to get the value of the selected option. what would the code look like. i have this:
quarter = frm1.quarter.options _
(frm1.quarter.options.selectedindex).text
but it comes back an error, saying "object requred"
thanks.
 
I'm assuming you have that inside a form?? Kind of hard to tell with so little code. I would set it up like this:


Code:
<form method="post" action="index.asp">
	<SELECT NAME="quarter" SIZE="1">
    	<OPTION>Select a Quarter</option>  
	    <OPTION>2005-Q1</option>     
	    <OPTION>2005-Q2</option>
	</SELECT>
	<br><input type="reset" value="Reset" name="B2"></p>
</form>

Once you submit it, or you could do a little javascript so it submits the form when you click a drop down item, either way once it's submitted the receiving page you would use this
Code:
<% 
  MyValue = request.form("quarter")
%>
 
there's no submit button. i have a link/ref that must pass this information to another program
 
You can have the dropdown menu submit itself without a button using this:
Code:
 <SELECT NAME="quarter" SIZE="1" onchange="this.form.submit();">
...
...
 
this submits the form when i make a selection. i want to select the fields without any actions. then when i click on the ref/link, i want the selection data and other stuff to be accompanied. here's my code:
Code:
strHTML = strHTML & "<td>" & "<a href=" & chr(34)   & "facility_stats_listing.asp?quarter=" & quarter & _    
"&row=1" & chr(34) & ">" & "</td>"
when i click this link, i want the selection to be included.

 
i'm not sure it's related to java. it's html/vbs question.
surely this can be done in vbscript. no?
 
Are you sure your form is named "frm1"???

You say you get an "object requred" message... what object is it complaining about?
 
vbs is also called asp, which is a server language. You have to submit the page back to the server to do that work. Or you can do javascript on the client side or try a combo of the two called AJAX(
Since your so determined to get this working with this method try this, it's something i used in the past and sounds like it would work for you.

In the <head>
Code:
<script language="JavaScript" type="text/JavaScript">
function updateinfo(iEventString){
	if ( iEventString =="0"){
		document.getElementById(iEventString + "div").innerHTML = "";
	}
	else {
		var myString = new String(iEventString);
		document.getElementById("MyLink").innerHTML = "<a href='facility_stats_listing.asp?quarter="+ iEventString +")'>Description<\/a>";
		};
	};
</script>

In the <body>
Code:
    <SELECT NAME="quarter" SIZE="1" onChange="updateinfo(this.value);">
        <OPTION value="0">Select a Quarter</option>  
        <OPTION value="2005-Q1">2005-Q1</option>     
        <OPTION value="2005-Q2">2005-Q2</option>
    </SELECT>

<div id="MyLink"></div>
 
TheCandyman,

You can write client-side scripts in VBS as well as JS, as long as you can live with the fact that the script will only work in I.E.

jfdabiri's code works fine for me, but when I rename the form to something else, I get an "Object required" on the form name... which is why i suspect that is the cause.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top