onclick event does not work with select option in IE

Discussion in 'Javascript' started by prash.marne@gmail.com, Jan 18, 2007.

  1. Guest

    Hello,

    I have a simple form

    <form method="POST">
    <select name="activity">
    <option value="0">None</option>
    <option value="M" onclick="popup_onclick()">Select
    Multiple</option>
    <option value="1">Kayaking</option>
    <option value="2">Rafting</option>
    <option value="3">Snowboarding & Skiing</option>
    <option value="4">Hiking</option>
    <option value="5">Trekking</option>
    </select>
    </form>

    & my javascript code is

    function popup_onclick(){
    my_window = window.open
    ("",'windowname','height=200,width=200');
    my_window.document.write("hellow world");
    my_window.document.close();
    }

    When a user views the form it shows a dropdown menu for activities &
    when she/he clicks on 'Select Multiple' option a new window should pop
    up with words written 'hellow world' in it .
    This works fine in Firefox 1.5 but it doesn't work in IE (Internet
    Explorer) 6.

    Anyone have any tips ? Can this be done in IE 6 ? Thanks!

    Prashant Marne
     
    , Jan 18, 2007
    #1
    1. Advertising

  2. marss Guest

    wrote:
    > Hello,
    >
    > I have a simple form
    >
    > <form method="POST">
    > <select name="activity">
    > <option value="0">None</option>
    > <option value="M" onclick="popup_onclick()">Select
    > Multiple</option>
    > <option value="1">Kayaking</option>


    Hi,
    Option element has no onclick event in IE. Use onchange event of select
    element instead.

    <select name="activity" onchange="if
    (this.options[this.selectedIndex].value=='M') popup_onclick();">
    <option value="0">None</option>
    <option value="M">Select Multiple</option>
    <option value="1">Kayaking</option>
    ......
     
    marss, Jan 18, 2007
    #2
    1. Advertising

  3. Guest

    marss,

    thx for the reply. appreciate it. however, i'm a bit surprised why
    internet explorer IE does not follow
    the HTML specifications.

    http://www.w3.org/TR/html401/interact/forms.html#h-17.6

    it writes that the <OPTION> part of the <SELECT> element does have an
    intrinsic event of onclick.

    thanks.

    prashant marne.

    ---------------------------------------------------------------------------------------------------------------------------------------------------------
    OPTION Attribute definitions

    selected [CI]
    When set, this boolean attribute specifies that this option is
    pre-selected.
    value = cdata [CS]
    This attribute specifies the initial value of the control. If this
    attribute is not set, the initial value is set to the contents of the
    OPTION element.
    label = text [CS]
    This attribute allows authors to specify a shorter label for an
    option than the content of the OPTION element. When specified, user
    agents should use the value of this attribute rather than the content
    of the OPTION element as the option label.

    Attributes defined elsewhere

    * id, class (document-wide identifiers)
    * lang (language information), dir (text direction)
    * title (element title)
    * style (inline style information)
    * disabled (disabled input controls)
    * onclick, ondblclick, onmousedown, onmouseup, onmouseover,
    onmousemove, onmouseout, onkeypress, onkeydown, onkeyup (intrinsic
    events)
    ---------------------------------------------------------------------------------------------------------------------------------------------------------


    marss wrote:
    > wrote:
    > > Hello,
    > >
    > > I have a simple form
    > >
    > > <form method="POST">
    > > <select name="activity">
    > > <option value="0">None</option>
    > > <option value="M" onclick="popup_onclick()">Select
    > > Multiple</option>
    > > <option value="1">Kayaking</option>

    >
    > Hi,
    > Option element has no onclick event in IE. Use onchange event of select
    > element instead.
    >
    > <select name="activity" onchange="if
    > (this.options[this.selectedIndex].value=='M') popup_onclick();">
    > <option value="0">None</option>
    > <option value="M">Select Multiple</option>
    > <option value="1">Kayaking</option>
    > .....
     
    , Jan 18, 2007
    #3
  4. ASM Guest

    a écrit :
    > i'm a bit surprised why
    > internet explorer IE does not follow
    > the HTML specifications.
    >
    > http://www.w3.org/TR/html401/interact/forms.html#h-17.6
    >
    > it writes that the <OPTION> part of the <SELECT> element does have an
    > intrinsic event of onclick.


    and what does mean "intrinsic" for you ?

    clicking on an option intrinsically changes selectedIndex

    --
    Stephane Moriaux et son (moins) vieux Mac déjà dépassé
    Stephane Moriaux and his (less) old Mac already out of date
     
    ASM, Jan 18, 2007
    #4
  5. ASM wrote:

    > a écrit :
    > > i'm a bit surprised why
    > > http://www.w3.org/TR/html401/interact/forms.html#h-17.6
    > >
    > > it writes that the <OPTION> part of the <SELECT> element does have an
    > > intrinsic event of onclick.

    >
    > and what does mean "intrinsic" for you ?
    >
    > clicking on an option intrinsically changes selectedIndex


    Not necessarily. The option in question might be already selected when
    clicked.

    --
    Bart
     
    Bart Van der Donck, Jan 18, 2007
    #5
  6. ASM Guest

    Bart Van der Donck a écrit :
    > ASM wrote:
    >>
    >> clicking on an option intrinsically changes selectedIndex

    >
    > Not necessarily. The option in question might be already selected when
    > clicked.


    and ?

    onclick changes selectedIndex to the same one :)

    --
    Stephane Moriaux et son (moins) vieux Mac déjà dépassé
    Stephane Moriaux and his (less) old Mac already out of date
     
    ASM, Jan 18, 2007
    #6
  7. ASM wrote:

    > Bart Van der Donck a écrit :
    > > ASM wrote:
    > >>
    > >> clicking on an option intrinsically changes selectedIndex

    > >
    > > Not necessarily. The option in question might be already selected when
    > > clicked.

    >
    > and ?
    >
    > onclick changes selectedIndex to the same one :)


    The verb "to change" semantically means "to become different, or to
    make different". A statement "change to the same" thus contradicts in
    its terms by definition.

    --
    Bart
     
    Bart Van der Donck, Jan 18, 2007
    #7
  8. ASM Guest

    Bart Van der Donck a écrit :
    > ASM wrote:
    >
    >> onclick changes selectedIndex to the same one :)

    >
    > The verb "to change" semantically means "to become different, or to
    > make different". A statement "change to the same" thus contradicts in
    > its terms by definition.


    Don't think browsers think so far and
    onclick=change ==> onclick = change to what asked
    (even if not different)

    But the way to change is not very important as soon as the result is
    what was expected.
    (any way last post was a joke and in previous one I used 'change' to
    point to select's event 'onchange' doing an intrinsic parallel)

    --
    Stephane Moriaux et son (moins) vieux Mac déjà dépassé
    Stephane Moriaux and his (less) old Mac already out of date
     
    ASM, Jan 18, 2007
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. J. Hall
    Replies:
    2
    Views:
    1,074
    Jeff Thies
    Apr 21, 2004
  2. Christopher Benson-Manica

    select option element onclick?

    Christopher Benson-Manica, Apr 20, 2004, in forum: Javascript
    Replies:
    1
    Views:
    134
    Matt Kruse
    Apr 20, 2004
  3. Replies:
    2
    Views:
    138
  4. Replies:
    0
    Views:
    106
  5. Moses
    Replies:
    3
    Views:
    191
Loading...

Share This Page