Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to invoke a combo box event?

Status
Not open for further replies.

SilverStray

Programmer
Oct 25, 2001
47
AU
Hi,

Instead of clicking over the combo box to see the drop down list, i want to simulate the dropping down of the list programmatically. How can I do this? Is there a way of invoking the function for MouseDown or on Click within my Javascript code? So instead of waiting for the event to occur (such as onClick or onMouseDown), what i want to do is to invoke that event.

I hope somebody out there can help!

Thanks in advance!



 
Hi,

Thanks for your reply. I tried it right away. But the click function doesn't seem to work. The 'click' event didn't cause the SELECT list to drop down.

I did something like this where I have a mySelect drop down list.

<input type=&quot;button&quot; name=&quot;testbtn&quot; value=&quot;Test&quot; onClick=&quot;form1.mySelect.change();&quot;>

I tried putting the other functions like select(), change(), but the error I get is: 'Object doesn't support this property or method.'
 
If I'm reading this right, what you want is for your list to drop down when the user mouses over the control rather than when they click the little triangle. Right in my interpretation?

If so, there is a way to do this. Select boxes are treated as system controls for the presentation aspect, meaning that we cannot (using script) tell the combo box to drop it's choices down on command.

What we can do is change the combo box to a list on the mouse over event as so:
Code:
<select size=&quot;1&quot; id=&quot;select1&quot; onMouseOver=&quot;this.size=this.options.length;&quot; onMouseOut=&quot;this.size=1;&quot;>
  <option>one</option>
  <option>two</option>
  <option>three</option>
</select>
 
hi,

I created a little tester .htm page for this, code below:
[tt]
<html>
<head>
<title>select event simulation</title>
</head>
<body>
<form name=&quot;form1&quot;>
<select name=&quot;MySelect&quot; size=&quot;1&quot;>
<option selected value=&quot;1&quot;>First Choice</option>
<option value=&quot;2&quot;>Second Choice</option>
<option value=&quot;3&quot;>Third Choice</option>
</select>
<br />
<input type=&quot;button&quot; name=&quot;button1&quot; value=&quot;focus( )&quot; onClick=&quot;MySelect.focus();&quot;>
<input type=&quot;button&quot; name=&quot;button2&quot; value=&quot;click( )&quot; onClick=&quot;MySelect.click();&quot;>
<input type=&quot;button&quot; name=&quot;button3&quot; value=&quot;selectedIndex=1&quot; onClick=&quot;MySelect.selectedIndex=1;&quot;>
<input type=&quot;button&quot; name=&quot;button4&quot; value=&quot;selectedIndex=2&quot; onClick=&quot;MySelect.selectedIndex=2;&quot;>
</form>
</body>
</html>
[/tt]

try this for the various options. [tt]MySelect.click();[/tt] runs alright, but unfortunately doesn't expand the select box. Doesn't look like there is a way to do this atm either.. you can however make a selection by changing the selectedIndex (note 0 is first choice) of the select.

g'luck
 
Doesn't look like there is a way to do this atm either

As outlined above, the only way to expand the list programatically is by manipulating the
Code:
size
attribute.
 
yep, guess you're right dwarfthrower: the only problem is changing the size attribute of the select box can throw off your entire page around the box: instead of the list dropdown appearing above the rest of the page it appears _IN_ the page, which could affect stuff in a carefully formatted page.

Just for original poster's info.

good luck, let us know if you were able to use anything
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top