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

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

P: n/a

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_something(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_id"
onchange="select_project_id(this)">
<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.
Sep 27 '07 #1
Share this Question
Share on Google+
14 Replies


P: n/a
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_something(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_id"
onchange="select_project_id(this)">
<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.SelectedIndex..

Oh well. The ways of Javascript passeth man's understanding etc.
Sep 27 '07 #2

P: n/a
On Sep 26, 7:53 pm, The Natural Philosopher <a...@b.cwrote:
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_something(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?

Sep 27 '07 #3

P: n/a
David Mark wrote:
On Sep 26, 7:53 pm, The Natural Philosopher <a...@b.cwrote:
>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_something(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.

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..

Sep 27 '07 #4

P: n/a
Lee
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_something(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
--

Sep 27 '07 #5

P: n/a
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_something(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.,
Sep 27 '07 #6

P: n/a
pr
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.
Sep 27 '07 #7

P: n/a

"The Natural Philosopher" <a@b.cwrote in message
news:11*****************@demeter.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_something(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?
Sep 27 '07 #8

P: n/a
pr wrote:
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.
Wasn't able to use the keyboard to do anything anyway in this case.

The help screen tells you to click...;-)
Sep 27 '07 #9

P: n/a
On Sep 27, 6:00 am, The Natural Philosopher <a...@b.cwrote:
David Mark wrote:
On Sep 26, 7:53 pm, The Natural Philosopher <a...@b.cwrote:
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_something(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.

Sep 27 '07 #10

P: n/a
Lee
The Natural Philosopher said:
>
Tim B wrote:
>"The Natural Philosopher" <a@b.cwrote in message
news:11*****************@demeter.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_something(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?

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.
--

Sep 27 '07 #11

P: n/a
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.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Sep 27 '07 #12

P: n/a
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.javascript FAQ -http://jibbering.com/faq/index.html
Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/
There is a lot here - and a lot of misunderstanding / 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...)

Sep 28 '07 #13

P: n/a
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 misunderstanding / communication
issues perhaps?
The two biggest misunderstanding/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.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Sep 28 '07 #14

P: n/a
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.
Oct 2 '07 #15

This discussion thread is closed

Replies have been disabled for this discussion.