Solved

Onchange problem more then one variable.

Posted on 2004-08-09
9
428 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now