473,386 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

<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_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
14 9176
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
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
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
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
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
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

"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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Andrea | last post by:
Hi, I'm trying to emulate part of our client-server application as a web site so customers can use it, and I'm stuck when it comes to re-ordering items in a list. Basically we have a list of...
1
by: Robert Kattke | last post by:
I'm designing a site for local music and entertertainment and have a few ?s that need to be cleared up. Currently, I'm working on the Club part and have a Contact Person form, and a Club form. ...
3
by: Iain Hallam | last post by:
Hi. I've been using display:none on the style property of some <option> elements in my forms, which works fine with Mozilla - as expected it removes the option from my dropdown (although it...
2
by: @sh | last post by:
Hi guys, As far as I understand it, there is no possible way to add an OnSelect/Onchange to an actual <option> within a select tag (to perhaps jump to a page or run a DOM command), is this still...
6
by: Chris Fink | last post by:
Does anyone know it is possible to include a small image(.gif .jpeg) within a <SELECT><option> so that the user would see the option text as well as a little image(icon) in the option? I know this...
6
by: joseph.lindley | last post by:
Forgive me for I am a bit of a web-dev novice - but I'm not doing too bad. I'm currently working with a bit of javascript to dynamically add <option>s into a select box. My code currently works...
5
by: Isha | last post by:
Hi all, I wanted to change the background color for only the first option in a select box, but following changed the background color for the whole dropdown box. <select name="alltags"...
4
by: Man-wai Chang | last post by:
-- iTech Consulting Co., Ltd. Expert of ePOS solutions Website: http://www.itech.com.hk (IE only) Tel: (852)2325 3883 Fax: (852)2325 8288
7
by: Shrek | last post by:
I have a drop down on a web page and want to change the cursor from default to pointer, so my style definition has style ="cursor: pointer;" the drop down though fails to change from the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.