Solved

Onchange problem more then one variable.

Posted on 2004-08-09
9
441 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to size popup in jquery mobile 4 63
Conformation code 4 37
Sticking text to shapes in Raphael.js 6 41
Javascript function 3 22
Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
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…
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…
Suggested Courses

752 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