User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 401,502 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,273 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 2529 | Replies: 7
Reply
Join Date: Feb 2008
Posts: 135
Reputation: TobbeK is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 3
TobbeK TobbeK is offline Offline
Junior Poster

Javscript Select onchange with ASP

  #1  
Feb 19th, 2008
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>
Last edited by TobbeK : Feb 19th, 2008 at 6:34 am.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2008
Location: Bangalore, India
Posts: 336
Reputation: DangerDev is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 32
DangerDev's Avatar
DangerDev DangerDev is offline Offline
Posting Whiz

Re: Javscript Select onchange with ASP

  #2  
Feb 19th, 2008
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
A computer lets you make more mistakes faster than any invention in human history - with the possible exceptions of handguns and tequila.
~Mitch Ratcliffe
Reply With Quote  
Join Date: Feb 2008
Posts: 135
Reputation: TobbeK is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 3
TobbeK TobbeK is offline Offline
Junior Poster

Re: Javscript Select onchange with ASP

  #3  
Feb 19th, 2008
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>
Reply With Quote  
Join Date: Jan 2008
Location: Bangalore, India
Posts: 336
Reputation: DangerDev is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 32
DangerDev's Avatar
DangerDev DangerDev is offline Offline
Posting Whiz

Re: Javscript Select onchange with ASP

  #4  
Feb 19th, 2008
learn some javascript, at least basics;
and some dom, it will help you to understand what i have written.
A computer lets you make more mistakes faster than any invention in human history - with the possible exceptions of handguns and tequila.
~Mitch Ratcliffe
Reply With Quote  
Join Date: Feb 2008
Posts: 135
Reputation: TobbeK is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 3
TobbeK TobbeK is offline Offline
Junior Poster

Re: Javscript Select onchange with ASP

  #5  
Feb 19th, 2008
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>
Last edited by TobbeK : Feb 19th, 2008 at 12:45 pm.
Reply With Quote  
Join Date: Jul 2005
Location: india
Posts: 143
Reputation: katarey is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 15
katarey's Avatar
katarey katarey is offline Offline
Junior Poster

Help Re: Javscript Select onchange with ASP

  #6  
Feb 19th, 2008
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
Freelance Web Designer & Developer
Http//www.Katarey.com
Reply With Quote  
Join Date: Feb 2008
Posts: 135
Reputation: TobbeK is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 3
TobbeK TobbeK is offline Offline
Junior Poster

Re: Javscript Select onchange with ASP

  #7  
Feb 22nd, 2008
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. :-)
Reply With Quote  
Join Date: Jul 2005
Location: india
Posts: 143
Reputation: katarey is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 15
katarey's Avatar
katarey katarey is offline Offline
Junior Poster

Re: Javscript Select onchange with ASP

  #8  
Feb 24th, 2008
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
Freelance Web Designer & Developer
Http//www.Katarey.com
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 2:32 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC