Is any way to fill an ASP variable at clientside with javascript.
I like to use that value to send as a string with a textlink like described below.

<SELECT ONCHANGE="location = this.options[this.selectedIndex].value;">
<option value="">Choose something</option>
<option value="0">------------------</option>
<option value="1">option 1</option>
<option value="2">option 2</option>
<option value="3">option 3</option>
<option value="4">option 4</option>
<option value="5">option 5</option>
<option value="6">option 6</option>
</SELECT>

Val = 'option value from the dropmenu'

a href = "testpage.asp?value=<%Response.Write(Val)%>"> Textlink </a>

hi
change last line of <a..... tag as follow
-put one id attribute there
then:
-using javascript's getElementById() function get that anchor element.
-change the attribute href using function:
element.setAttribute("href","link_str");
-link_str is the complete text link string.

using above method you can dynamically change href attribute of anchor tag

Hi, thanks for the reply. I'm not a javascripter so I need some more examples where to place the items


<SELECT ONCHANGE="link_str = element.setAttribute("href","link_str");">
<option value="">Choose something</option>
<option value="0">------------------</option>
<option value="1">option 1</option>
<option value="2">option 2</option>
<option value="3">option 3</option>
<option value="4">option 4</option>
<option value="5">option 5</option>
<option value="6">option 6</option>
</SELECT>


<a href = "testpage.asp?value=link_str">Textlink</a>

learn some javascript, at least basics;
and some dom, it will help you to understand what i have written.

Nope, doesn't work

I use this one instead, it makes a page reload but I can live with that.

<form id=frm action=select_menu.asp method=post>
<select name=optval onchange=frm.submit()>")
<option value="">Choose something</option>
<option value="">------------------</option>
<option value="1">option 1</option>
<option value="2">option 2</option>
<option value="3">option 3</option>
<option value="4">option 4</option>
<option value="5">option 5</option>
<option value="6">option 6</option>
</select>
</form>

<a href="menu.asp?id=<%=request.form("optval")%>">Link</a>

Hi There,
I have Seen your Code and found that you are using frm.submit() function, in this function "frm" is the name of the form which you want submit, but you haven't define any name in form tag,

This Code Will Work

<form name="frm" action="test.asp" method="post">
  <select name="optval" onchange="frm.submit()">
    <option value="">Choose something</option>
    <option value="">------------------</option>
    <option value="1">option 1</option>
    <option value="2">option 2</option>
    <option value="3">option 3</option>
    <option value="4">option 4</option>
    <option value="5">option 5</option>
    <option value="6">option 6</option>
  </select>
</form>
<a href="menu.asp?id=<%=request.form("optval")%>">Link</a>

and you can do same thing with only using JavaScript:

Example:

<script type="text/javascript">
<!--//
//<![CDATA[
function changeHref(){
	var linkToChange = document.getElementById('linkToChange');
	linkText = "menu.asp?id="+document.getElementById('optval').value;
	linkToChange.href = linkText;
}
//]]>
//-->
</script>

 <select name="optval" onchange="changeHref()" id="optval">
    <option value="">Choose something</option>
    <option value="">------------------</option>
    <option value="1">option 1</option>
    <option value="2">option 2</option>
    <option value="3">option 3</option>
    <option value="4">option 4</option>
    <option value="5">option 5</option>
    <option value="6">option 6</option>
  </select>
<a href="" id="linkToChange">Link</a>

Hope this will help you,

Rahul Dev Katarey

Thanks Kataray

Works great as long as value has been chosen.
The link (url) must be there even if no value has been set. So I'm back on square 1 again. :-)

Thats OK, just put a default links src for a tag, function will work as is,

<a href="menu.asp" id="linkToChange">Link</a>
or
<a href="menu.asp?id=what ever you want" id="linkToChange">Link</a>

thanks
Rahul Dev Katarey

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.