onChange problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Omar

    onChange problem

    Hi,

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

    <select name='id' onChange="windo w.location='deP aso.jsp?nombre= id&valor="+this .options[this.selectedIn dex].value+"'">

    TIA
  • David Dorward

    #2
    Re: onChange problem

    Omar wrote:
    [color=blue]
    > Could you please tell me what am I doing wrong in the next sentence?[/color]



    --
    David Dorward <http://blog.dorward.me .uk/> <http://dorward.me.uk/>
    Home is where the ~/.bashrc is

    Comment

    • Lee

      #3
      Re: onChange problem

      Omar said:[color=blue]
      >
      >Hi,
      >
      >Could you please tell me what am I doing wrong in the next sentence?
      >
      ><select name='id'
      >onChange="wind ow.location='de Paso.jsp?nombre =id&valor="+thi s.options[this.selectedIn dex].value+"'">
      >[/color]

      You want (this.options[this.selectedIn dex].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="windo w.location=this .options[this.selectedIn dex].value"

      Comment

      • RobB

        #4
        Re: onChange problem

        Omar wrote:[color=blue]
        > Hi,
        >
        > Could you please tell me what am I doing wrong in the next sentence?
        >
        > <select name='id'[/color]
        onChange="windo w.location='deP aso.jsp?nombre= id&valor="+this .options[this.selectedIn dex].value+"'">[color=blue]
        >
        > TIA[/color]

        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="windo w.location='deP aso.jsp?nombre= id&valor='+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...

        Comment

        • DU

          #5
          Re: onChange problem

          Omar wrote:
          [color=blue]
          > Hi,
          >
          > Could you please tell me what am I doing wrong in the next sentence?
          >
          > <select name='id' onChange="windo w.location='deP aso.jsp?nombre= id&valor="+this .options[this.selectedIn dex].value+"'">
          >
          > TIA[/color]

          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.locatio n.href = 'dePaso.jsp?nom bre=id&amp;valo r=' +
          this.options[this.selectedIn dex].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.locatio n.href =
          'dePaso.jsp?nom bre=id&amp;valo r=' +
          this.options[this.selectedIn dex].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 :)

          Comment

          Working...