Solved

Onchange problem more then one variable.

Posted on 2004-08-09
9
425 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

747 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

17 Experts available now in Live!

Get 1:1 Help Now