Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Onchange problem more then one variable.

Posted on 2004-08-09
9
Medium Priority
?
446 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 
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 2000 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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

722 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