473,800 Members | 2,383 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Drop down selext box options using external JS not working in IE

Hello all,

I'm having a problem with a user preferences form I'm creating. I want
to use dynamic dropdown SELECT boxes for this so my page doesn't get
cluttered with 100000 links.

Since I have 10000 Options embedded in the SELECT tags, I'm using an
External JS file to display them. I'm using these same Options for
different SELECT tags, so they can be "re-used (or looped)", instead of
writing them over and over again.

This is working PERFECTLY in Mozilla/Firefox 1.5 and Opera 9. The
dropdown boxes display exactly how I want, they render just the same as
they would in a normal embedded Options list. However, Internet
Explorer 5, 5.5 and 6.0 (and maybe also 7, haven't tested this) all
render the Options "outside" of the dropdown boxes, as plain text, so
they can't be clicked (and thus no value can be set). For some weird
reason IE CAN read embedded JS between SELECT tags, but not external???

Here's the example I'm using:

<form id="MyForm">

<select name='colorset'
onchange='addst yle(\"body\",th is.options[this.selectedIn dex].value,
this.id+\"_\"+t his.selectedInd ex);'>

<script type='text/javascript' src='colorjs.js '></script>

</select>

</form>

External .JS file:
document.write( '<OPTION value=\"color:# ffffff\">White</OPTION>');
document.write( '<OPTION value=\"color:# 003366\">Darkbl ue</OPTION>');
The above example will NOT work in IE. It simply renders a blank
dropdown with the options outside of the dropdown box

However, the following example DOES work in IE, this time it's embedded
and NOT external.

<form id="MyForm">

<select name='colorset'
onchange='addst yle(\"body\",th is.options[this.selectedIn dex].value,
this.id+\"_\"+t his.selectedInd ex);'>

<script type='text/javascript'docu ment.write('<OP TION
value=\"color:# ffffff\">White</OPTION>'); document.write( '<OPTION
value=\"color:# 003366\">Darkbl ue</OPTION>') </script>

</select>

</form>

Is there any workaround for IE? I have like 100000 options, embedding
it normally would result in an at least 2mb JS file (which we don't
want, takes ages to load). I've already tried several other methods,
but to no avail.

Any help would be GREATLY appreciated...

Aug 11 '06 #1
3 3027
se*******@hotma il.com wrote:
Since I have 10000 Options embedded in the SELECT tags
IMO, that's mistake #1.
10,000 options in a select tag is not user-friendly.
Consider an alternate way to achieve your goal.
<select name='colorset'
onchange='addst yle(\"body\",th is.options[this.selectedIn dex].value,
this.id+\"_\"+t his.selectedInd ex);'>
<script type='text/javascript' src='colorjs.js '></script>
</select>
Instead, inside the select make a function call:
<script type="text/javascript">
writeOptions();
</script>

Then inside your external script, wrap all the document.write( ) calls in a
function.

Also, many write() calls may be quite a bit slower than building up one
string and doing a write() once.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Aug 11 '06 #2
Thank you so mutch! It's working perfectly crossbrowser now. Another
"Aha!" moment for me there, not so expierenced with JS (yet :-P).

Matt Kruse wrote:
>IMO, that's mistake #1.
10,000 options in a select tag is not user-friendly.
Consider an alternate way to achieve your goal.
With "10000 options" I meant the same options being used over and over
again, not 10000 individual options. Now I can call one group of
options everytime I want it to appear in a different SELECT tag, so it
loads fast and properly.

Matt Kruse wrote:
Also, many write() calls may be quite a bit slower than building up one
string and doing a write() once.
"Optimizing ", as I like to call it, happens when the design is in it's
final stages and works perfectly. As of now, I like to seperate every
individual option which is easier for me to edit, same for the CSS :-).

Thanks again, I didn't knew the solution was that easy :-)

Aug 11 '06 #3
won't it be a little easier using this instead

var opt1 as String();
var opt1 = '<option value=\"color:# ffffff\">white</option>\n';
var opt1 = opt1 + 'option value=\"color:# 003366\">darkbl ue</option>\n';

\\ and in the end just do document.write( opt1);
should be a lot faster i think.

--------------------------
My websites
http://www.eecpworld.com/
http://www.indiapropertyhome.com/
http://www.wahmdirect.com/
http://www.indianmatrimonialnet.com/

*** Sent via Developersdex http://www.developersdex.com ***
Aug 11 '06 #4

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

Similar topics

2
11062
by: ehm | last post by:
I am working on creating an editable grid (for use in adding, deleting, and editing rows back to an Oracle database). I have a JSP that posts back to a servlet, which in turns posts to a WebLogic SFSB and, from there, to the database. On the front end, all cells appear as text fields. However, for certain cells, when the user clicks on the cell, the text field turns into a drop-down field (i.e. Select object), defaulting to the value...
6
15423
by: Greg Scharlemann | last post by:
I am attempting to populate a drop down menu based on the selection of a different drop down menu. However, it is not working correctly, I cannot figure out for the life of me what exactly happens because I am not getting any errors on the page. <html> <script language="javascript"> var phaseArray = new phaseArray(4); var phaseTypeId = new phaseTypeId(4); var phaseId = new phaseId(4);
1
6368
by: Greg Scharlemann | last post by:
I would like to automatically populate a drop down menu when the page loads based on the selection of an item in a different drop down menu. I made a test page that when drop down #1 changes, drop down #2 populates. Does anyone know how to get drop down #2 to populate based on what is selected in drop down #1 when the page loads? Here is my test code: ************************************************************************ <html>...
3
23335
by: Darren | last post by:
Please Help Me!! I've created a typical <form> and a <select> element. The options are created dynamically from my access database (using asp). There are about 70 options, and when you click the dropdown button, it shows about 25 (depending on screen resolution) and then the gives you a scroll bar to get to the rest. My question is, can I limit the number of options shown when you click
1
1945
by: Vic Spainhower | last post by:
I have 2 drop-down menus (1) States (2) Shows By State. My question is how do I invoke a re-build of the Shows By State drop-down when the user requests a different state. I believe this has to be done with Javascript and I don't know Javascript. Could someone supply a small example of how this is done? I am using PHP and MySQL. Following is the PHP code for building the state drop-down menu: <tr><td bgcolor="#EFC891" width="496"...
19
9085
by: nazgulero | last post by:
Hello all, I wonder if anybody can give me a hint about what I have to do to get this working: I am creating a drop down box using the script below. The result is two text fields; now I want to pass those values, which come from the drop down box, to the next page. The next page should then simply look like this:
3
2997
by: John Walker | last post by:
Hi, On an ASP.NET page I have a drop down list control. When the user pulls down the list and makes a selection, I perform validation, and if the validation fails I want the selected item in the drop down box to go back to what the value was before the user tried to change it, but at that point I will not know what the original value was. Or is there a drop down control "revert" method, or is there any way of knowing what the original...
3
4448
by: scott | last post by:
Hello all, I am ripping my hair out over this and maybe someone could help. I have a site that has groups and subgroups of those groups that all have int id's. I am trying to have a multiple select drop down (could select more than one group) like the following:
4
2776
by: audreyality | last post by:
I am new to javascript and appreciate any guidance on this issue, so thank you in advance for your advice! Situation: I am working with a form that will send information to a database. I need the following: A drop-down box of options that onChange=... Opens another drop-down box of unique options that onChange=... Displays text dependent on which option you chose. An example:
0
9691
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10505
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10253
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10035
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9090
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6813
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2945
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.