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

Dynamic Link... 1

Status
Not open for further replies.

mitch77

Programmer
Nov 16, 2000
42
PT
Hi,

I have a combobox and a link object in an html page. When a user click that link, the value of the href, must be the value of the combobox in that moment.
how can i implement this using javascript?

thanks,
Mitch

There is my code:

<script LANGUAGE=JAVASCRIPT>
<!--
function function1(){
return './destinationpage.asp?'+form1.combo1.value
}
//-->
</script>

(...)

<form method=&quot;post&quot; name=&quot;form1&quot;>

A Href=&quot;javascript:function1();&quot;>Link1</a>

<select name=&quot;combo1&quot; size=1>
<option value=&quot;1&quot; selected>option1</option>
<option value=&quot;2&quot; selected>option2</option>
<option value=&quot;3&quot; selected>option3</option>
<option value=&quot;4&quot; selected>option4</option>
(...)
</select>
</form>
 
There's two things about your code:

1. Why don't you use your form to get to the other page (see attached code).
2. Why do you have all the values in the combobox selected, while the size of the combobox is 1?

Anyways, code below will do what you want it to do:

<script LANGUAGE=JAVASCRIPT>
<!--
function function1(){
document.form1.action = './destinationpage.asp?'+form1.combo1.value;
document.form1.submit();
}
//-->
</script>

<form method=&quot;post&quot; name=&quot;form1&quot;>

<a href=&quot;javascript:function1();&quot;>Link1</a>

<select name=&quot;combo1&quot; size=1>
<option value=&quot;1&quot;>option1</option>
<option value=&quot;2&quot;>option2</option>
<option value=&quot;3&quot;>option3</option>
<option value=&quot;4&quot;>option4</option>
</select>
</form>

Hope this helps...

<webguru>iqof188</webguru>
 
Thank you For the help.

It Works, But, There's no other way to do that?
This is because there are many options, and i want to do that without submitting the form.
I forgot to told, but the Combobox is dynamic.

Thanks, Mitch
 
function function1(){
document.location.href= './destinationpage.asp?'+form1.combo1.value;
}

but anyway this will go to destinationpage.asp?blahblah and the form won't be here anymore !!!!! you can't change page and at the same time remain on the same page !!! unless you want to open a new page ??? and as iqof188 i find it weird to select ALL options ... even if it's dynamic !
 
quick IE solution, place the link outside of the form and give it an id:

<a href=&quot;1&quot; id=&quot;mylink&quot;>

<form>
<select onChange=&quot;mylink.href='this.value' name=&quot;combo1&quot; size=1>
<option value=&quot;1&quot;>option1</option>
<option value=&quot;2&quot;>option2</option>
<option value=&quot;3&quot;>option3</option>
<option value=&quot;4&quot;>option4</option>
</select> jared@aauser.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top