select box - using refresh to select same item twice

Discussion in 'Javascript' started by entfred@hotmail.com, Jul 25, 2006.

  1. Guest

    I was experimenting with trying to select the same item in a select box
    twice in a row
    and found out that you need to do a refresh (view - refresh) in
    Internet Explorer. This is
    so you can click on the same item twice "in a row" to select it.

    Does anyone know how to automatically make a web page do a refresh when
    the web
    page loads? This would prevent the user from having to do the refresh,
    themselves.

    An example select box would be

    <select name="colors" onChange="form1.submit();">
    <option value="red">red</option><option
    value="blue">blue</option><option value="green">green</option><option
    value="purple">purple</option>
    </select>

    A typical scenario:

    1. The user clicks on blue
    2. form1 is submitted
    3. The user presses the browser back button
    4. The user clicks on red
    5. form1 is submitted
    6. The user presses the browser back button
    7. The user clicks on red
    8. nothing happens, since onChange did not detect a "change".

    In other words, how do you click on red twice?

    Any workarounds on how to do a refresh or something to get around this
    above scenario
    are highly appreciated!

    --- Entfred
    , Jul 25, 2006
    #1
    1. Advertising

  2. bobzimuta Guest

    wrote:
    > Does anyone know how to automatically make a web page do a refresh when
    > the web
    > page loads? This would prevent the user from having to do the refresh,
    > themselves.
    >
    > An example select box would be
    >
    > <select name="colors" onChange="form1.submit();">
    > <option value="red">red</option><option
    > value="blue">blue</option><option value="green">green</option><option
    > value="purple">purple</option>
    > </select>
    >
    > A typical scenario:
    >
    > 1. The user clicks on blue
    > 2. form1 is submitted
    > 3. The user presses the browser back button
    > 4. The user clicks on red
    > 5. form1 is submitted
    > 6. The user presses the browser back button
    > 7. The user clicks on red
    > 8. nothing happens, since onChange did not detect a "change".
    >
    > In other words, how do you click on red twice?


    As a matter of consideration to limited access users (keyboard only)
    it's not advised to submit forms when a select element is cycled. They
    will always be forced to submit on the second selection. Rather, it is
    better to accompany a submit button with the select. That would solve
    your problem, as well.
    bobzimuta, Jul 25, 2006
    #2
    1. Advertising

  3. RobG Guest

    wrote:
    > I was experimenting with trying to select the same item in a select box
    > twice in a row
    > and found out that you need to do a refresh (view - refresh) in
    > Internet Explorer. This is
    > so you can click on the same item twice "in a row" to select it.


    That approach has serious usability issues as described by bobzimuta.
    It is generally a bad idea to use onchange with a select for anything,
    or to use onchange on any form control to submit a form.

    However, to address the other parts of your question...


    > Does anyone know how to automatically make a web page do a refresh when
    > the web
    > page loads? This would prevent the user from having to do the refresh,
    > themselves.


    You can use window.onload to reset the form.


    > An example select box would be
    >
    > <select name="colors" onChange="form1.submit();">


    Using the form name this way is not a good idea. If the select is a
    control of form1, use:

    <select ... onchange="this.form.submit();">

    Otherwise use:

    <select ... onchange="document.forms['form1'].submit();">


    The way you have used it 'works', but it is easy to break.


    > <option value="red">red</option><option
    > value="blue">blue</option><option value="green">green</option><option
    > value="purple">purple</option>
    > </select>
    >
    > A typical scenario:
    >
    > 1. The user clicks on blue


    Given that red is the first option (and probably the default selected),
    selecting it won't fire the onchange handler. Given your scenario, the
    first option must be blank or other invalid selection to force the user
    to change it and fire the onchange handler. As a result, you can't
    have a useful default selection, users *must* change the selection. If
    you allow the user to select an option, then submit the form, they can
    choose any value and you can set a useful default.

    > 2. form1 is submitted


    If they are using keyboard navigation, IE will submit the form as soon
    as they navigate up or down using a cursor key. onchange is supposed
    to fire when the control loses focus, IE does it prematurely in this
    case.

    [...]

    > --- Entfred


    The correct way to add a signature is to have two dashes, a space and a
    return on a line by themselves. That allows news readers to
    automatically trim the signature when quoting.


    --
    Rob.
    RobG, Jul 26, 2006
    #3
    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. Kiuhnm

    twice(twice(x))

    Kiuhnm, Apr 1, 2006, in forum: C++
    Replies:
    2
    Views:
    393
    Kiuhnm
    Apr 1, 2006
  2. =?Utf-8?B?SmFtZXMgR2V1cnRz?=

    Bug with nested repeaters. Item events are called twice per item

    =?Utf-8?B?SmFtZXMgR2V1cnRz?=, Mar 15, 2007, in forum: ASP .Net
    Replies:
    4
    Views:
    966
    =?Utf-8?B?SmFtZXMgR2V1cnRz?=
    Mar 28, 2007
  3. Rajesh.V

    Same user twice in the same aspx..

    Rajesh.V, Aug 6, 2003, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    135
    Rajesh.V
    Aug 6, 2003
  4. palmiere
    Replies:
    1
    Views:
    396
    Erwin Moller
    Feb 9, 2004
  5. Andy Fish
    Replies:
    1
    Views:
    100
    Csaba Gabor
    Jun 15, 2005
Loading...

Share This Page