<select..onchange() > with only one <option>

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • The Natural Philosopher

    <select..onchange() > with only one <option>


    This is a nasty one and I can't see my way out of it.

    I have a bunch of select statements in a form, and each select statement
    has an onchange="do_so mething(this)" in it, and this works
    nicely..except when there is only ONE OPTION in a given select.
    It seems you cannot 'onchange' a single option!

    Well, that is reasonable.

    The trouble is I have no way of selecting it since the form itself is a
    dummy: The form action is basically to submit to a new script with
    hidden variables carefully set to get the desired action depending on
    the last option selected..

    onclick() in the <optionitself doesn't work for IE6...

    Can anyone think of a way to achieve what I want?


    The fragment in question is this one

    <TR><TD align="center"> <b>Julian's Projects</b></td>
    <TD align="center"> <select STYLE="width: 200px" name="project_i d"
    onchange="selec t_project_id(th is)">
    <OPTION value= "13" >ME-262 (Sep 13th 07)</OPTION>
    </select></TD></TR>

    This works stunningly with more than one option..but falls apart with
    just one.

    The option of making the single option SELECTED is a non starter, as
    there are other options in other select statements that deselect this
    one..once deselected I can't ever get it back!

    I think I tried an onclick() on the whole select thing, but it didn't
    work too well.


  • The Natural Philosopher

    #2
    Re: &lt;select..onc hange() &gt; with only one &lt;option&g t;

    The Natural Philosopher wrote:
    >
    This is a nasty one and I can't see my way out of it.
    >
    I have a bunch of select statements in a form, and each select statement
    has an onchange="do_so mething(this)" in it, and this works
    nicely..except when there is only ONE OPTION in a given select.
    It seems you cannot 'onchange' a single option!
    >
    Well, that is reasonable.
    >
    The trouble is I have no way of selecting it since the form itself is a
    dummy: The form action is basically to submit to a new script with
    hidden variables carefully set to get the desired action depending on
    the last option selected..
    >
    onclick() in the <optionitself doesn't work for IE6...
    >
    Can anyone think of a way to achieve what I want?
    >
    >
    The fragment in question is this one
    >
    <TR><TD align="center"> <b>Julian's Projects</b></td>
    <TD align="center"> <select STYLE="width: 200px" name="project_i d"
    onchange="selec t_project_id(th is)">
    <OPTION value= "13" >ME-262 (Sep 13th 07)</OPTION>
    </select></TD></TR>
    >
    This works stunningly with more than one option..but falls apart with
    just one.
    >
    The option of making the single option SELECTED is a non starter, as
    there are other options in other select statements that deselect this
    one..once deselected I can't ever get it back!
    >
    I think I tried an onclick() on the whole select thing, but it didn't
    work too well.
    >
    >
    Hmm., I seem to have fixed it by replacing onchange() with onclick()

    It seems that onclick(this) picks up the correct value in
    this.SelectedIn dex..

    Oh well. The ways of Javascript passeth man's understanding etc.


    Comment

    • David Mark

      #3
      Re: &lt;select..onc hange() &gt; with only one &lt;option&g t;

      On Sep 26, 7:53 pm, The Natural Philosopher <a...@b.cwrot e:
      This is a nasty one and I can't see my way out of it.
      >
      I have a bunch of select statements in a form, and each select statement
      has an onchange="do_so mething(this)" in it, and this works
      nicely..except when there is only ONE OPTION in a given select.
      It seems you cannot 'onchange' a single option!
      >
      Well, that is reasonable.
      >
      The trouble is I have no way of selecting it since the form itself is a
      dummy: The form action is basically to submit to a new script with
      hidden variables carefully set to get the desired action depending on
      the last option selected..
      >
      onclick() in the <optionitself doesn't work for IE6...
      >
      Can anyone think of a way to achieve what I want?
      Why use a select at all if there is only one option? Wouldn't a
      hidden input make more sense?

      Comment

      • The Natural Philosopher

        #4
        Re: &lt;select..onc hange() &gt; with only one &lt;option&g t;

        David Mark wrote:
        On Sep 26, 7:53 pm, The Natural Philosopher <a...@b.cwrot e:
        >This is a nasty one and I can't see my way out of it.
        >>
        >I have a bunch of select statements in a form, and each select statement
        >has an onchange="do_so mething(this)" in it, and this works
        >nicely..exce pt when there is only ONE OPTION in a given select.
        >It seems you cannot 'onchange' a single option!
        >>
        >Well, that is reasonable.
        >>
        >The trouble is I have no way of selecting it since the form itself is a
        >dummy: The form action is basically to submit to a new script with
        >hidden variables carefully set to get the desired action depending on
        >the last option selected..
        >>
        >onclick() in the <optionitself doesn't work for IE6...
        >>
        >Can anyone think of a way to achieve what I want?
        >
        Why use a select at all if there is only one option? Wouldn't a
        hidden input make more sense?
        >
        Firstly because once the user has added more stuff there IS more than
        one option, and secondly because there are more options in more boxes
        elsewhere.

        I used SELECT/OPTION as a handy way of generating various pop up lists
        without going to deep into Javascript.

        There are several lists, all with one or more options..I need to select
        ONE item from ALL the lists and go with that.


        The javascript associated with the onchange() or onclick() stuff does
        indeed patch in a value to a hidden variable anyway.

        Anyway, using onclick() worked except the client is saying it doesn't in
        IE7 and I haven't got that to test with. Ah well.

        If all else fails I may ye write it with pure javascript pop up klists
        and ditch option/select altogether..





        Comment

        • Lee

          #5
          Re: &lt;select..onc hange() &gt; with only one &lt;option&g t;

          The Natural Philosopher said:
          >
          >
          >This is a nasty one and I can't see my way out of it.
          >
          >I have a bunch of select statements in a form, and each select statement
          >has an onchange="do_so mething(this)" in it, and this works
          >nicely..exce pt when there is only ONE OPTION in a given select.
          >It seems you cannot 'onchange' a single option!
          So you have the same problem if their choice happens to be the
          default selection.
          The traditional solution is to provide a dummy first option
          with text like "Choose one..." and make your onchange handler
          return without action if selectedIndex<1


          --

          Comment

          • The Natural Philosopher

            #6
            Re: &lt;select..onc hange() &gt; with only one &lt;option&g t;

            Lee wrote:
            The Natural Philosopher said:
            >>
            >This is a nasty one and I can't see my way out of it.
            >>
            >I have a bunch of select statements in a form, and each select statement
            >has an onchange="do_so mething(this)" in it, and this works
            >nicely..exce pt when there is only ONE OPTION in a given select.
            >It seems you cannot 'onchange' a single option!
            >
            So you have the same problem if their choice happens to be the
            default selection.
            The traditional solution is to provide a dummy first option
            with text like "Choose one..." and make your onchange handler
            return without action if selectedIndex<1
            >
            >
            As I said, onclick works..its perfect on my selection of browsers..just
            need to see whats happening in Ie7.

            The user who reported it is not that computer savvy, so the problem
            report is indecipherable till I get on site next week.,

            Comment

            • pr

              #7
              Re: &lt;select..onc hange() &gt; with only one &lt;option&g t;

              The Natural Philosopher wrote:
              As I said, onclick works..its perfect on my selection of browsers..just
              need to see whats happening in Ie7.
              Not if you use the keyboard it doesn't.

              Comment

              • Tim B

                #8
                Re: &lt;select..onc hange() &gt; with only one &lt;option&g t;


                "The Natural Philosopher" <a@b.cwrote in message
                news:1190904446 .38749.12@demet er.uk.clara.net ...
                Lee wrote:
                The Natural Philosopher said:
                >
                This is a nasty one and I can't see my way out of it.
                >
                I have a bunch of select statements in a form, and each select
                statement
                has an onchange="do_so mething(this)" in it, and this works
                nicely..except when there is only ONE OPTION in a given select.
                It seems you cannot 'onchange' a single option!
                So you have the same problem if their choice happens to be the
                default selection.
                The traditional solution is to provide a dummy first option
                with text like "Choose one..." and make your onchange handler
                return without action if selectedIndex<1
                As I said, onclick works..its perfect on my selection of browsers..just
                need to see whats happening in Ie7.
                >
                The user who reported it is not that computer savvy, so the problem
                report is indecipherable till I get on site next week.,
                Why would the user click it if there is only one option?


                Comment

                • The Natural Philosopher

                  #9
                  Re: &lt;select..onc hange() &gt; with only one &lt;option&g t;

                  pr wrote:
                  The Natural Philosopher wrote:
                  >As I said, onclick works..its perfect on my selection of
                  >browsers..ju st need to see whats happening in Ie7.
                  >
                  Not if you use the keyboard it doesn't.
                  Wasn't able to use the keyboard to do anything anyway in this case.

                  The help screen tells you to click...;-)

                  Comment

                  • David Mark

                    #10
                    Re: &lt;select..onc hange() &gt; with only one &lt;option&g t;

                    On Sep 27, 6:00 am, The Natural Philosopher <a...@b.cwrot e:
                    David Mark wrote:
                    On Sep 26, 7:53 pm, The Natural Philosopher <a...@b.cwrot e:
                    This is a nasty one and I can't see my way out of it.
                    >
                    I have a bunch of select statements in a form, and each select statement
                    has an onchange="do_so mething(this)" in it, and this works
                    nicely..except when there is only ONE OPTION in a given select.
                    It seems you cannot 'onchange' a single option!
                    >
                    Well, that is reasonable.
                    >
                    The trouble is I have no way of selecting it since the form itself is a
                    dummy: The form action is basically to submit to a new script with
                    hidden variables carefully set to get the desired action depending on
                    the last option selected..
                    >
                    onclick() in the <optionitself doesn't work for IE6...
                    >
                    Can anyone think of a way to achieve what I want?
                    >
                    Why use a select at all if there is only one option? Wouldn't a
                    hidden input make more sense?
                    >
                    Firstly because once the user has added more stuff there IS more than
                    one option, and secondly because there are more options in more boxes
                    elsewhere.
                    Then you would change the UI at the point where there is more than one
                    option. Other options in other boxes don't enter into it unless those
                    are what trigger the change in the UI.

                    >
                    I used SELECT/OPTION as a handy way of generating various pop up lists
                    without going to deep into Javascript.
                    It sounds more like you used form elements because you need to
                    populate and submit a form.
                    >
                    There are several lists, all with one or more options..I need to select
                    ONE item from ALL the lists and go with that.
                    But if one has only one option, then it doesn't need a visible form
                    element.
                    >
                    The javascript associated with the onchange() or onclick() stuff does
                    indeed patch in a value to a hidden variable anyway.
                    So your select with one option could just be a hidden input to start
                    with.
                    >
                    Anyway, using onclick() worked except the client is saying it doesn't in
                    IE7 and I haven't got that to test with. Ah well.
                    The onclick event does not indicate a change of the input element's
                    value.
                    >
                    If all else fails I may ye write it with pure javascript pop up klists
                    and ditch option/select altogether..
                    If you need to populate and submit a form, then I think you should use
                    a form.

                    Comment

                    • Lee

                      #11
                      Re: &lt;select..onc hange() &gt; with only one &lt;option&g t;

                      The Natural Philosopher said:
                      >
                      >Tim B wrote:
                      >"The Natural Philosopher" <a@b.cwrote in message
                      >news:119090444 6.38749.12@deme ter.uk.clara.ne t...
                      >>Lee wrote:
                      >>>The Natural Philosopher said:
                      >>>>This is a nasty one and I can't see my way out of it.
                      >>>>>
                      >>>>I have a bunch of select statements in a form, and each select
                      >statement
                      >>>>has an onchange="do_so mething(this)" in it, and this works
                      >>>>nicely..exc ept when there is only ONE OPTION in a given select.
                      >>>>It seems you cannot 'onchange' a single option!
                      >>>So you have the same problem if their choice happens to be the
                      >>>default selection.
                      >>>The traditional solution is to provide a dummy first option
                      >>>with text like "Choose one..." and make your onchange handler
                      >>>return without action if selectedIndex<1
                      >>>>
                      >>>>
                      >>As I said, onclick works..its perfect on my selection of browsers..just
                      >>need to see whats happening in Ie7.
                      >>>
                      >>The user who reported it is not that computer savvy, so the problem
                      >>report is indecipherable till I get on site next week.,
                      >>
                      >Why would the user click it if there is only one option?
                      >>
                      >>
                      >Because as I have patiently explained, there are other options in other
                      >select windows. These are all mutually exclusive.
                      You haven't explained why, if one of the select objects is already
                      showing the value that the user wants to choose, they should be
                      expected click on it.

                      That's not how people are used to interacting with selection lists.

                      Explaining that "you have to treat these select objects differently
                      than any others that you've used" probably isn't the best design.


                      --

                      Comment

                      • Randy Webb

                        #12
                        Re: &lt;select..onc hange() &gt; with only one &lt;option&g t;

                        The Natural Philosopher said the following on 9/27/2007 6:00 AM:

                        <snip>
                        If all else fails I may ye write it with pure javascript pop up klists
                        and ditch option/select altogether..
                        It should be a hoot to watch you try to write a "pure javascript popup
                        klists" (whatever a klist is) when you can't even understand why your
                        present code doesn't work.

                        --
                        Randy
                        Chance Favors The Prepared Mind
                        comp.lang.javas cript FAQ - http://jibbering.com/faq/index.html
                        Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

                        Comment

                        • Aaron Saray

                          #13
                          Re: &lt;select..onc hange() &gt; with only one &lt;option&g t;

                          On Sep 27, 12:29 pm, Randy Webb <HikksNotAtH... @aol.comwrote:
                          The Natural Philosopher said the following on 9/27/2007 6:00 AM:
                          >
                          <snip>
                          >
                          If all else fails I may ye write it with pure javascript pop up klists
                          and ditch option/select altogether..
                          >
                          It should be a hoot to watch you try to write a "pure javascript popup
                          klists" (whatever a klist is) when you can't even understand why your
                          present code doesn't work.
                          >
                          --
                          Randy
                          Chance Favors The Prepared Mind
                          comp.lang.javas cript FAQ -http://jibbering.com/faq/index.html
                          Javascript Best Practices -http://www.JavascriptT oolbox.com/bestpractices/
                          There is a lot here - and a lot of misunderstandin g / communication
                          issues perhaps? Anyways, here are my thoughts:

                          You may want to write a script that executes body.onload to check any
                          of those select boxes and populate the hidden input fields with the
                          current index selected of each drop down (this fits into what I
                          _THINK_ you're trying to do...)

                          Another thing is to know dynamically in your generating script if you
                          have only one option. If it is, generate all of the content ahead of
                          time (ie, fill your hidden inputs, make the select box possibly a
                          dummy - with no id/name, etc...)

                          Comment

                          • Randy Webb

                            #14
                            Re: &lt;select..onc hange() &gt; with only one &lt;option&g t;

                            Aaron Saray said the following on 9/28/2007 12:06 AM:
                            On Sep 27, 12:29 pm, Randy Webb <HikksNotAtH... @aol.comwrote:
                            >The Natural Philosopher said the following on 9/27/2007 6:00 AM:
                            >>
                            ><snip>
                            >>
                            >>If all else fails I may ye write it with pure javascript pop up klists
                            >>and ditch option/select altogether..
                            >It should be a hoot to watch you try to write a "pure javascript popup
                            >klists" (whatever a klist is) when you can't even understand why your
                            >present code doesn't work.
                            >>
                            <snipped signature that shouldn't have been quoted>
                            There is a lot here - and a lot of misunderstandin g / communication
                            issues perhaps?
                            The two biggest misunderstandin g/communication issues would be:

                            1) Your inability to reply to the right person.
                            2) Your inability to properly trim posts when replying (signatures in
                            particular).
                            Anyways, here are my thoughts:
                            OK. Along with mine.
                            You may want to write a script that executes body.onload to check any
                            of those select boxes and populate the hidden input fields with the
                            current index selected of each drop down (this fits into what I
                            _THINK_ you're trying to do...)
                            You are replying to me and that leaves me no choice but to assume you
                            are referring to me. Given that, why in the world would *I* want to
                            execute body.onload? Nor does it "fit into what I am trying to do".
                            Another thing is to know dynamically in your generating script if you
                            have only one option. If it is, generate all of the content ahead of
                            time (ie, fill your hidden inputs, make the select box possibly a
                            dummy - with no id/name, etc...)
                            The simplest solution to the problem that you are referring to (that
                            isn't my problem but someone else's) is to always have the first option
                            be "Make a selection" and then have the selections after that. Then, the
                            user chooses one and, guess what, the onchange fires and all the
                            problems miraculously go away. The funny thing about that simple
                            solution is that it doesn't involve body.onload, window.onload or
                            anything.onload , just a little thought is all. And, that solution has
                            been suggested more than once in this thread.

                            --
                            Randy
                            Chance Favors The Prepared Mind
                            comp.lang.javas cript FAQ - http://jibbering.com/faq/index.html
                            Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

                            Comment

                            • The Natural Philosopher

                              #15
                              Re: &lt;select..onc hange() &gt; with only one &lt;option&g t;

                              Aaron Saray wrote:
                              On Sep 27, 12:29 pm, Randy Webb <HikksNotAtH... @aol.comwrote:
                              >The Natural Philosopher said the following on 9/27/2007 6:00 AM:
                              >>
                              ><snip>
                              >>
                              >>If all else fails I may ye write it with pure javascript pop up klists
                              >>and ditch option/select altogether..
                              >It should be a hoot to watch you try to write a "pure javascript popup
                              >klists" (whatever a klist is) when you can't even understand why your
                              >present code doesn't work.
                              >>
                              Oh I understand why it doesn't work all right.

                              As I said in my original post.

                              However as I also said, it now does. To the specification I want anyway.


                              Sorry for not replying earlier. Been on a short holiday.

                              Comment

                              Working...