Solved

Onchange problem more then one variable.

Posted on 2004-08-09
9
436 Views
Last Modified: 2012-06-21
I have a form with lots of fields among them two select-fields.
The first selectfield is ok, it has this function:
onchange="top.location.href='add_content.asp?mainsection=' + this.options[this.selectedIndex].value">
The other select-field should also go to this URL, but I need two values to be passed when onchange.

For example this (does not work)
onchange="top.location.href='add_content.asp?content_type=<%=content_type%>&mainsection=' + this.options[this.selectedIndex].value">

How can I do this?

Wahooo
0
Comment
Question by:wahooo
9 Comments
 
LVL 33

Expert Comment

by:sajuks
ID: 11750727
<form name="form1" method="post" >
  <select name="State" onChange="top.location.href='http://www.google.com?mainsection=' + this.options[this.selectedIndex].value+'&value2='+this.options[this.selectedIndex].value">
   <option value="" selected="true">Choose</option>
   <option value="New York">New York</option>
   <option value="Puerto Ric">Puerto Ric</option>
   <option value="Virgin Isl">Virgin Isl</option>
  </select>
  <input name="submited" type="submit" id="submit2" value="Continue">
</form>



0
 
LVL 33

Expert Comment

by:sajuks
ID: 11750746
The syntax would be
top.location.href= 'url?variable1='+variable1value+'&variable2='+variable2value+.....so on
0
 

Author Comment

by:wahooo
ID: 11750748
the other value is stored in asp as a string:
content_type = "example"
How do I put that value in as value2 = <%=content_type%>

wahooo
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 33

Expert Comment

by:sajuks
ID: 11750792
You cant access asp value in the same page as your javascript. You are trying to mix up your server side and client side code.
0
 
LVL 33

Accepted Solution

by:
sajuks earned 500 total points
ID: 11750817
oops , try this
onChange="top.location.href='a1.asp?content_type=' + <%=content_type%>+'&mainsection='+this.options[this.selectedIndex].value">

0
 
LVL 30

Expert Comment

by:third
ID: 11750843
onchange="top.location='add_content.asp?content_type=<%=content_type%>&mainsection=' + this.options[this.selectedIndex].value">

should work. can you post the client-side script (i.e after executing the asp page)?

should look like,

onchange="top.location='add_content.asp?content_type=Content Type Value&mainsection=' + this.options[this.selectedIndex].value">
0
 
LVL 30

Expert Comment

by:third
ID: 11750847
well, i guess sajuks already figured it out. ;-)
0
 
LVL 30

Expert Comment

by:third
ID: 11750858
err, i'm reading too fast. looks like not gonna work on my second reading...
0
 
LVL 1

Expert Comment

by:garethdart24
ID: 11751146
This is a bit of a stab in the dark, but:

Read the content-type variable into a hidden text field in the form when the page loads:

<input type = "hidden" value = "<%=content_type%>" id = "hiddenContentType" name = "hiddenContentType">

then you can access it as below:

<html>
<head>
<script>

function sbonchange() {

//comment out
alert("add_content.asp?&mainsection=" + document.getElementById('State').value + "&value2=" + document.getElementById('hiddenContentType').value);

uncomment
//top.location.href = "add_content.asp?&mainsection=" + document.getElementById('State').value + "&value2=" + document.getElementById('hiddenContentType').value

}

</script>
</head>
<body>
<br />

<form name="form1" method="post" >
  <select id = "State" name="State" onChange="sbonchange();">
   <option value="" selected="true">Choose</option>
   <option value="New York">New York</option>
   <option value="Puerto Ric">Puerto Ric</option>
   <option value="Virgin Isl">Virgin Isl</option>
  </select>

<input id = "hiddenContentType" name = "hiddenContentType" type = "hidden" value = "example">

  <input name="submitted" type="submit" id="submit2" value="Continue">
</form>


</body>
</html>
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question