473,382 Members | 1,400 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,382 software developers and data experts.

Adding option elements to select on focus

I am attempting to dynamically add an option to a select box when the
box is selected (click or focus). This works fine using Firefox by
either creating a new element and appending it to the SELECT's
children, or by creating a new Option() and setting it to the
select.options array.

My problem is in IE whenever it adds the element the select box does
not drop down. For instance if I have my code run onFocus when the
select box is clicked the option is added and the box does not drop
down. If I click it a second time while it still has focus it will
display the new value.

Is there a trick or work around to have IE handle this the same as FF?

thanks,
jc
Mar 14 '08 #1
1 2731
SAM
Josh C. a écrit :
I am attempting to dynamically add an option to a select box when the
box is selected (click or focus). This works fine using Firefox by
either creating a new element and appending it to the SELECT's
children, or by creating a new Option() and setting it to the
select.options array.

My problem is in IE whenever it adds the element the select box does
not drop down. For instance if I have my code run onFocus when the
select box is clicked the option is added and the box does not drop
down. If I click it a second time while it still has focus it will
display the new value.

Is there a trick or work around to have IE handle this the same as FF?
IE doesn't leave focus so easily

add : this.options.selectedIndex = this.options.length-1;

try also : onmousedown (... ? ! ! ? )

<script type="text/javascript">
function extend(quoi) {
quoi = quoi.elements['ici'];
quoi.length=0;
for(var i=0; i<20; i++)
quoi.options[quoi.length] = new Option(i, i);
quoi.options.selectedIndex=quoi.length-1;
}
</script>
<form action="#" onsubmit="return confirm('sure?');">
<p><select name='ici' onfocus="extend(this.form);">
<option>test</option>
</select>
</form>

My browsers (IE Mac Fx ...) works all the same : while you don't click
outside the select, focus stay on it and the function do not more fire.
Mar 14 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Robin Johnson | last post by:
Hello, I'm writing some dynamic forms code for running on a PocketPC (running Windows 2003). There is to be a set of select menus, and choosing a particular option in one menu changes the...
10
by: David | last post by:
Can anyone give me a quick code snippet (that is standards-based) for adding OPTION tags to a SELECT dynamically. I have no problem doing it in IE but I am kind of new to the whole standards world...
4
by: domas | last post by:
Hi, I can't get my semi-dynamic form to work. Maybe you could help. I've got a simple form with a select box. And a button that, when clicked, creates another copy if the select box and places...
6
by: Chameleon | last post by:
In the code below I want to alert the selected option of select. In Mozilla the code works (If I choose "3" alerts it). In IE alerts: nothing appear --------------------- <script> function hi()...
6
by: artev | last post by:
if I have a select with more options, how I can know if is there an option selected; is necessary a cycle? or is there an inner property?
1
by: shankwheat | last post by:
I'm trying to add an option to a select box dynamically. A typical string value is delimitted by a # character. There will always be only one option to add. What's happening is that the option...
3
by: nayeemquayum | last post by:
Hello every body, I was trying to populate a drop down box using ajax/javascript function. My jsp page has a select tag like this <select name="compSelect" onChange="changeElement();">...
1
by: Daniel Jung | last post by:
Hi Please take a look at http://lingo.uib.no/daniel/testcase5/ where I made a (surprising) testcase (and a screenshot), involving padding-left and negative text-indent on option elements (right...
1
Prakash Gnana
by: Prakash Gnana | last post by:
How to remove a particular option in select box in HTML when clicked?
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.