Forum Moderators: open

Message Too Old, No Replies

Javascript to generate a link depending of 2 combos values

Using javascript to generate dinamic links

         

creatiu

1:39 pm on Oct 30, 2006 (gmt 0)

10+ Year Member


Hello everybody,

I have a form with two combos (menu list). One of them contain categories (each one with a value number). The another one a long list with countries (each one with a value number too).

I need an script to modify a default link like this:
www.somesite.com/search/(load_value1)/(load_value2)

Form sample:

-----------------------

Category: [Cateogry 7]
Country: [Country 34]

[BUTTON]

-----------------------

Now if I click this [BUTTON] I should go to:
www.somesite.com/search/value_category7/value_country34

SOMEONE CAN HELP ME? Thank you!

eelixduppy

1:18 pm on Nov 1, 2006 (gmt 0)



Welcome to WebmasterWorld!

Here's a quick example:


<html>
<body>
<script type="text/javascript">
<!--
function GoToLink()
{
document.location.href = 'www.somesite.com/search/'+document.form.option1.value+'/'+document.form.option2.value;

}
//-->
</script>
<form name="form">
<select name="option1">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<select name="option2">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<br />
<input type="button" onClick="GoToLink();" value="Go!" />
</form>
</body>
</html>

Best of luck!

rocknbil

5:47 pm on Nov 1, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't think that works with drop down lists, you need to access the value by the selected index:

document.location.href = 'www.somesite.com/search/'+ document.form.option1.options[form.option1.selectedIndex].value+ '/'+document.form.option2.options[form.option2.selectedIndex].value;