By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,654 Members | 1,575 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,654 IT Pros & Developers. It's quick & easy.

onChange problem

P: n/a
Hi,

Could you please tell me what am I doing wrong in the next sentence?

<select name='id' onChange="window.location='dePaso.jsp?nombre=id&va lor="+this.options[this.selectedIndex].value+"'">

TIA
Jul 23 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Omar wrote:
Could you please tell me what am I doing wrong in the next sentence?


http://www.cs.tut.fi/~jkorpela/forms/navmenu.html

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Jul 23 '05 #2

P: n/a
Lee
Omar said:

Hi,

Could you please tell me what am I doing wrong in the next sentence?

<select name='id'
onChange="window.location='dePaso.jsp?nombre=id&v alor="+this.options[this.selectedIndex].value+"'">


You want (this.options[this.selectedIndex].value) to be evaluated
at the time that the onchange handler fires.

As written, it is evaluated at the time that you define the handler.
Try:

onchange="window.location=this.options[this.selectedIndex].value"

Jul 23 '05 #3

P: n/a
Omar wrote:
Hi,

Could you please tell me what am I doing wrong in the next sentence?

<select name='id' onChange="window.location='dePaso.jsp?nombre=id&va lor="+this.options[this.selectedIndex].value+"'">
TIA


Those double-quotes bounding the onchange handler string go around the
*entire* string; the singles are the ones you need to delimit the
literal part of the url (and discontinue, to insert a variable):

<select name="id"
onChange="window.location='dePaso.jsp?nombre=id&va lor='+this.value">

Select.value is pretty ubiquitous these days, someone will correct me
if that's inaccurate.

Might want to hook up a button to do this, users are notorious for
fumbling listboxes...

Jul 23 '05 #4

P: n/a
DU
Omar wrote:
Hi,

Could you please tell me what am I doing wrong in the next sentence?

<select name='id' onChange="window.location='dePaso.jsp?nombre=id&va lor="+this.options[this.selectedIndex].value+"'">

TIA


1- name="id" is a very bad choice of name value. And id="name" is also a
bad choice of id value. name="name" and id="id" are also bad choices.
Using the same string to identify both the name and id attributes is
also a bad coding practice.

2- In your code, it is more robust to use
window.location.href =

3- I think you are not using quotes accordingly. How about:

onchange = "window.location.href = 'dePaso.jsp?nombre=id&amp;valor=' +
this.options[this.selectedIndex].value;">

4- You also need to escape "&" in the href/query string to avoid
validation problems and make sure you're not referring to a named
character entity reference.

So, I would recommend:

<select onchange = "window.location.href =
'dePaso.jsp?nombre=id&amp;valor=' +
this.options[this.selectedIndex].value;">

if id is related to the select, then you need to adjust your code
accordingly with this.id in the query string.

DU
--
The site said to use Internet Explorer 5 or better... so I switched to
Mozilla 1.7.6 :)
Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.