View Full Version : Useing javascript in a href
Crash1hd
01-22-2003, 08:11 AM
I need to link to a file useing a href type link that in the file its linking to has a dropdown menu with nothing initaly selected but when you click the link I want to have it select one of the options by default!
for example
<a href="edit.asp?PurchaseField=50">50 Words</a>
<select size="1" name="PurchaseField">
<option value="10">Select Here</option>
<option value="50">50 Word</option>
<option value="100">100 Word</option>
<option value="250">250 Word</option>
<option value="350">350 Word</option>
<option value="400">Unlimited</option>
any thoughts anyone! :)
Just Like a search engine would :)
Thanks
Adam
What are u trying to say?
explain more plz...:o
Mhtml
01-22-2003, 09:31 AM
Like you click the link "50 words" and then the next page which contains a dropdown menu will have the option "50 words" already selected?
That's how I interpreted the question. :)
Crash1hd
01-22-2003, 12:34 PM
Thats Exactly what I am trying to do! :) I am just not sure how! if there is something in asp or javascript that I can do mostly javascript but if asp thats ok also
an example is on google when you put in what you want to search for it automatically puts it in the same form field on the next page may not be a drop down but same concept! :)
Mhtml
01-22-2003, 01:01 PM
Well, me not being a javascript guru I'm not much help there but if you didn't mind using ASP then I can help. :)
<%
Select Case Request.QueryString("PurchaseField")
Case 10
S10 = "Selected"
Case 50
S50 = "Selected"
Case 100
S100 = "Selected"
Case 250
S250 = "Selected"
Case 350
S350 = "Selected"
Case "Unlmited"
S400 = "Selected"
End Select
%>
<option <%=S10%> value="10">Select Here</option>
<option <%=S50%> value="50">50 Word</option>
<option <%=S100%> value="100">100 Word</option>
<option <%=S250%> value="250">250 Word</option>
<option <%=S350%> value="350">350 Word</option>
<option <%=S400%> value="400">Unlimited</option>
arnyinc
01-22-2003, 01:29 PM
You'll get the same result, but you can do it with less serverside processing this way:
page1.htm
<a href="buh.asp?PurchaseField=50">link</a>
buh.asp
<html>
<head>
<script language="javascript">
function set_dropdown(yourObj){
for (var i=0; i<yourObj.length; i++)
if (yourObj.options[i].value=='<%=request.querystring("purchasefield")%>')
yourObj.options[i].selected=true;
}
</script>
</head>
<body onLoad="set_dropdown(document.myform.PurchaseField)">
<form name="myform">
<select size="1" name="PurchaseField">
<option value="10">Select Here</option>
<option value="50">50 Word</option>
<option value="100">100 Word</option>
<option value="250">250 Word</option>
<option value="350">350 Word</option>
<option value="400">Unlimited</option>
</select>
</form>
</body>
</html>
Mhtml
01-22-2003, 01:40 PM
Difference in run-time should be almost nothing.
whammy
01-23-2003, 12:53 AM
Uhh... what are you trying to do? This might be even easier, depending upon the desired result. Can you explain the end goal? :)
Crash1hd
01-23-2003, 06:57 AM
Exactly what mhtmn said
Like you click the link "50 words" and then the next page which contains a dropdown menu will have the option "50 words" already selected?
I have an html page that has multiple links on them that takes me to page 2 on page 2 is a form page that has a drop down menu that depending on which link was choosen Ie 50 words and another that says 100 words so when the person clicks on the link to 50 words then the drop down menu for 50 words is preselected but when you click the link for 100 words the same drop down menu now selects 100 words ext... and if you where to go to that page by itself then another selection is choosen
:) I will try the asp ones see if they do what I am looking for
Thanks for all the help so far!
Ok I have tried both and the one that arnyinc put up is the one that worked the best does exactly what I am looking for Thanks everyone :)
Crash1hd
01-24-2003, 09:16 AM
I have another question! How would I make the above script work if the value of the drop down is a script? for example
javascript:HideShow();ShowDObits()
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.