select box behavior - do something even if no change

L

lawpoop

I'm writing a javascript function to run when a user selects a value
in a select box.

I've been playing around with the example usage of onMouseOver,
onMouseDown, onMouseUp, onChange, onBlur, onFocus with a select input.
The event onChange comes the closest, but from my testing, if there is
a default value, and the user clicks on the select box, looks at the
list, and re-selects the original answer, the event isn't fired -- of
course, because it fires on a change :)

I don't think I can use the onMouseUp or onClick, because those events
can be triggered just to drop down the menu on the select box. What I
would need to use is the onMouseUp of the actual menu selection.

Since I'm re-writing html that appears immediately below the select
box, I don't want to use onBlur, because then the user might lose
their cursor when the html changes.

What's the best way to solve this problem?
 
T

Thomas 'PointedEars' Lahn

lawpoop said:
I'm writing a javascript function to run when a user selects a value
in a select box.

I've been playing around with the example usage of onMouseOver,
onMouseDown, onMouseUp, onChange, onBlur, onFocus with a select input.
[...]

I don't think I can use the onMouseUp or onClick, because those events
can be triggered just to drop down the menu on the select box. What I
would need to use is the onMouseUp of the actual menu selection.

`select' elements should not be abused for menus to begin with.
But maybe that was but a poor choice of words on your part.
Since I'm re-writing html that appears immediately below the select
box, I don't want to use onBlur, because then the user might lose
their cursor when the html changes.

I don't follow. If that was an issue, then when the `select' element was
focused the user would "lose their cursor" anyway. Handling the `blur'
event of a control has nothing to do with calling the blur() method of a
control. In fact, calling the blur() method does not cause the `blur' event
to be created because the action was not directly initiated by the user.
What's the best way to solve this problem?

Put a button next to the `select' element and "re-write" the "html" when it
is clicked. That is common practice, and therefore application behavior as
expected by the user. It is also the only way to make that part of the
application accessible.


PointedEars
 
T

Tom Cole

lawpoop said:
I'm writing a javascript function to run when a user selects a value
in a select box.
I've been playing around with the example usage of onMouseOver,
onMouseDown, onMouseUp, onChange, onBlur, onFocus with a select input.
[...]
I don't think I can use the onMouseUp or onClick, because those events
can be triggered just to drop down the menu on the select box. What I
would need to use is the onMouseUp of the actual menu selection.

`select' elements should not be abused for menus to begin with.
But maybe that was but a poor choice of words on your part.
Since I'm re-writing html that appears immediately below the select
box, I don't want to use onBlur, because then the user might lose
their cursor when the html changes.

I don't follow.  If that was an issue, then when the `select' element was
focused the user would "lose their cursor" anyway.  Handling the `blur'
event of a control has nothing to do with calling the blur() method of a
control.  In fact, calling the blur() method does not cause the `blur' event
to be created because the action was not directly initiated by the user.
What's the best way to solve this problem?

Put a button next to the `select' element and "re-write" the "html" when it
is clicked.  That is common practice, and therefore application behavior as
expected by the user.  It is also the only way to make that part of the
application accessible.

PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee

Let's say your select box has id "mySelect"

<body onload="document.getElementById('mySelect').onchange();">

HTH
 
L

lawpoop

Let's say your select box has id "mySelect"

<body onload="document.getElementById('mySelect').onchange();">

HTH

Yes, but that isn't exactly what I want, because they could "select"
the default value. Then there's no change, and therefore no launching
of the script.
 
T

Thomas 'PointedEars' Lahn

lawpoop said:
Yes, but that isn't exactly what I want, because they could "select"
the default value. Then there's no change, and therefore no launching
of the script.

You are mistaken. There is a chance that the above could work when
the document is loaded, but of course it does not work afterwards,
and you are looking for the latter.


PointedEars
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top