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

Using JavaScript to dynamically update a page 1

Status
Not open for further replies.

MarkRuse

Programmer
Aug 11, 1999
29
GB
The below code will display two HTML SELECT boxes. When the user changes the first one when the page is loaded the second one gets populated with data which relates to what the user has selected.<br>
<br>
The Code works fine but I am now trying to put some finishing touches to it, and I have now blown the doors off.<br>
<br>
What I need to do is to take the rest of the data the user has placed on the form and send them back to same page via JS in a GET format. (thispage.asp?Category=5&Title=HELLO etc). The object passed into the JS function seems to be just the value of the selected option from the select box. How can I get to pass an object to JS which will allow me to work with the rest of the objects within the page ?<br>
<br>
I have only been fiddling with JS and VBS for a few weeks, so please let me know if I have missed the point.<br>
<br>
function GetSubCategoryList(Category) <br>
{<br>
this.location = "thispage.asp?Category=" + Category.value<br>
}<br>
<br>
&lt;select name="Category" size="1" onChange="GetSubCategoryList(Category)" language="JavaScript"&gt;<br>
<br>
&lt;% SQL = "Select Name,CategoryID From Category ORDER BY Name"<br>
<br>
RSCategory.Open SQL,Conn,1,2 <br>
Response.Write("&lt;OPTION VALUE=0&gt;") & vbcrlf<br>
Do While Not RSCategory.EOF <br>
if clng(RSCategory("CategoryID")) = clng(request.querystring("Category")) then<br>
Response.Write("&lt;OPTION SELECTED VALUE=" & trim(RSCategory("CategoryID")) & "&gt;" & RSCategory("Name")) & vbcrlf <br>
else<br>
Response.Write("&lt;OPTION VALUE=" & trim(RSCategory ("CategoryID")) & "&gt;" & RSCategory("Name")) & vbcrlf<br>
end if<br>
RSCategory.MoveNext<br>
Loop<br>
<br>
RSCategory.Close<br>
%&gt; <br>
&lt;/select&gt;<br>
<br>
&lt;select name="SubCategory" size="1"&gt;<br>
<br>
&lt;% if request.querystring("Category") = "" and request.querystring("Category") = 0 then<br>
else<br>
SQL = "Select SubCategoryID , Name From SubCategory WHERE SubCategory.CategoryID = " & request.querystring("Category") & " ORDER BY Name" ' <br>
<br>
Response.Write("&lt;OPTION&gt;" & trim(SQL))<br>
RSCategory.Open SQL,Conn,1,2 <br>
Do While Not RSCategory.EOF<br>
Response.Write("&lt;OPTION VALUE=" & RSCategory("SubCategoryID") & "&gt;" & trim(RSCategory("Name"))) & vbcrlf<br>
RSCategory.MoveNext<br>
Loop<br>
<br>
RSCategory.Close<br>
Conn.Close<br>
end if<br>
%&gt; <br>
&lt;/select&gt;
 
I have just worked it out. Please correct me if I am wrong, but it seems to be that you can only get a handle on a object by going through the form.<br>
<br>
ie. document.formname.formitem.value<br>
<br>

 
that is correct...almost: you can also use document.forms[x].inputs[y].value to return the value of text-input box number y (numbering starts @ 0) on form x (numbering also starts @ 0).<br>
If you want to get parameters passed to the page through the URL, you can also set a variable equal to window.location then split it @ the "?" and at any subsequent "&"s to "parse" the URL info into a form that you would be *much* more likely able to use.<br>
<br>
-Robherc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top