opening a combo box from JS

L

Laser Lips

Hi, I have a select box and I'd like to open it from JavaScript. Is
this possible?
I don't think it is but just in case one of you knew.
I've tried combo.click(); ..focus() ..select()
Graham
 
T

Thomas 'PointedEars' Lahn

Gregor said:
Laser Lips meinte:

No.

Before dismissing the idea entirely, I think it would be worthwhile to
investigate if it was feasible to create an input event and dispatch it
to the control, so that the control might show the desired behavior.


PointedEars
 
S

SAM

Gregor Kofler a écrit :
Laser Lips meinte:

No.

select box == <input type="select"> ?
open == choice an item of the list (show an option) ?

if yes :

document.myForm.mySelect.selectedIndex = 2;


JS :
====

function showOption(item) {
var s = document.myForm.mySelect, o = s.options;
for(var i=0, n=o.length; i<n; i++)
if(o.text == item) {
s.selectedIndex = i;
break;
}
}

function launchOption(item) {
var s = document.myForm.mySelect, o = s.options;
for(var i=0, n=o.length; i<n; i++)
if(o.text == item) {
location = o.value;
break;
}
}

HTML :
======

<form name="myForm">
<select name="mySelect">
<option value="http://www.google.com/">Google</option>
<option value="http://www.yahoo.com/">Yahoo!</option>
<option value="http://en.wikipedia.org/">Wiki</option>
</select>
</form>
<button onclick="showOption('Yahoo!')">Show Yahoo!</button>
<button onclick="launchOption('Wiki')">Go to Wikipedia</button>
 
G

Gregor Kofler

Thomas 'PointedEars' Lahn meinte:
Before dismissing the idea entirely, I think it would be worthwhile to
investigate if it was feasible to create an input event and dispatch it
to the control, so that the control might show the desired behavior.

I doubt that - it would be a click event dispatched to the control, and
then I think it is completely up to the browser's behaviour whether
you'd get the according "visual feedback". Anyway, it won't be easy -
most likely - and it won't work on "most browsers". I suppose it would
be easier and more "cross browser" to fake a dropdown entirely with an
ordinary input plus other block elements (like all those suggest widgets).

Gregor
 
G

Gregor Kofler

SAM meinte:
Gregor Kofler a écrit :

select box == <input type="select"> ?
open == choice an item of the list (show an option) ?

[code snipped]

So what? That selects an option, but it won't "drop" the list of the
dropdown. At least that's what I think the OP want's.

Gregor
 
G

Gregor Kofler

Thomas 'PointedEars' Lahn meinte:
Gregor Kofler wrote:
SAM meinte:
select box == <input type="select"> ?
open == choice an item of the list (show an option) ?
[code snipped]

So what? That selects an option, [...]

Does it? `select' is not a (Valid) value for the `type' attribute of the
`input' element in the first place.

I didn't understand those two lines and just skipped them. I was
referring to the snipped code below. I should have snipped everything...

Gregor
 
T

Thomas 'PointedEars' Lahn

Gregor said:
SAM meinte:
Gregor Kofler a écrit :
select box == <input type="select"> ?
open == choice an item of the list (show an option) ?

[code snipped]

So what? That selects an option, [...]

Does it? `select' is not a (Valid) value for the `type' attribute of the
`input' element in the first place.


PointedEars
 
S

SAM

Gregor Kofler a écrit :
SAM meinte:
Gregor Kofler a écrit :

select box == <input type="select"> ?
open == choice an item of the list (show an option) ?

[code snipped]

it won't "drop" the list of the dropdown.

Do not understand what that means (dropping)
(translation word to word in french has no meaning)
perhaps a picture of the feature ?

or do you mean something like :
Unwind, unfold(display), show all the list ?
 
S

SAM

Gregor Kofler a écrit :
SAM meinte:


Yes.

OK.

function openDropdown() {
var s = document.myForm.mySelect;
s.size = o.length
}
function closeDropdown() {
var s = document.myForm.mySelect;
s.size = '';
}

:)
 
L

Laser Lips

Gregor Kofler a écrit :



OK.

function openDropdown() {
var s = document.myForm.mySelect;
s.size = o.length}

function closeDropdown() {
var s = document.myForm.mySelect;
s.size = '';

}

:)

That would not work because it would push everything below it down.

Don't think it it's possible.

Graham
 
S

SAM

Laser Lips a écrit :
That would not work because it would push everything below it down.

there was a smiley !
Don't think it it's possible.

certainly something as a tiptool could simulate the feature

here is using simple css :

<style type="text/css">
form p { position: relative; height: 1em }
form p select { position: absolute; z-index: 100 }
</style>

works (if it could say) in Firefox, Safari
not tested IE

<http://cjoint.com/data/iAmOH3aFc7_open_select.htm>
 

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,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top