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

Using proper DOM with dynamic select arrays

Based on a condition, I want to add new options into a form's SELECT
menu.

This method has been working for Firefox, but not IE/Opera/Avant:
document.form1.aem_from[0]=new Option("[ select ]","X");

(Although the Firefox JavascriptConsole would of course tell me it's
not good.)

Trying to get it to work in every other browser than Firefox...how the
heck to I format that using proper DOM?

I've tried:
document.getElementById('aem_from'[0])=new Option("[ select ]","X");
and with various other placements of quotes and positioning of the
array brackets, like:
document.getElementById('aem_from')[0]=new Option("[ select ]","X");
and:
document.getElementById('aem_from[0]')=new Option("[ select ]","X");
and it none of it works in any browser and the Console simply says I
have an "invalid assignment left-hand side".

I tried doing a search on the newsgroup...but I can't find anything
quite like this. Maybe threads that are similar, but I didn't grok it
enough to carry over the lesson given. My understanding of JavaScript
is less "understanding" and more "seething hatred of a necessary evil
in my life." =)

Thanks for any suggestions!
Liam

Jul 23 '05 #1
2 2807
n...@celticbear.com wrote:
Based on a condition, I want to add new options into a form's SELECT
menu.

This method has been working for Firefox, but not IE/Opera/Avant:
document.form1.aem_from[0]=new Option("[ select ]","X");

(Although the Firefox JavascriptConsole would of course tell me it's
not good.)

Trying to get it to work in every other browser than Firefox...how the heck to I format that using proper DOM?

I've tried:
document.getElementById('aem_from'[0])=new Option("[ select ]","X");
and with various other placements of quotes and positioning of the
array brackets, like:
document.getElementById('aem_from')[0]=new Option("[ select ]","X");
and:
document.getElementById('aem_from[0]')=new Option("[ select ]","X");
and it none of it works in any browser and the Console simply says I
have an "invalid assignment left-hand side".

I tried doing a search on the newsgroup...but I can't find anything
quite like this. Maybe threads that are similar, but I didn't grok it
enough to carry over the lesson given. My understanding of JavaScript
is less "understanding" and more "seething hatred of a necessary evil
in my life." =)

Thanks for any suggestions!
Liam


document.getElementById() just gets you the element (object) with that
id set - if it exists - or returns null. Start with that:

document.getElementById('aem_from')

Then reference the first Options[] slot:

document.getElementById('aem_from').options[0]

....and add your new option:

document.getElementById('aem_from').options[0]=new Option("[ select
]","X");

As you can see - you did that already, at least the shorthand version
(no reference to the options collection). Did you give the listbox an
id as well as a name?

Jul 23 '05 #2
RobB wrote:
....
document.getElementById('aem_from').options[0]=new Option("[ select
]","X");

As you can see - you did that already, at least the shorthand version
(no reference to the options collection). Did you give the listbox an
id as well as a name?


That did it. Amazing what just a period will do. =/

Yeah, all the rest of my naming was fine, I just needed to know to put
that period there. =P

Thanks for the reply!!
Liam

Jul 23 '05 #3

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

Similar topics

8
by: Drew | last post by:
I am trying to build a small app that shows a Course Title from the database, then displays a dropdown full of categories for the user to choose one... I thought a loop would be the best way to...
2
by: taras.di | last post by:
Hi everyone, I've been reading up on how to create a drop down box who's context is dynamically produced based on the value of a previous select box. I've read a lot about some of the browsers...
11
by: efrat | last post by:
Hello, I'm planning to use Python in order to teach a DSA (data structures and algorithms) course in an academic institute. If you could help out with the following questions, I'd sure...
9
by: uidzer0 | last post by:
Hey everyone, Taken the following code; is there a "proper" or dynamic way to allocate the length of line? #include <stdio.h> #include <errno.h> int main(int argc, char **argv) { FILE *fp;
4
by: vaiism | last post by:
I am trying to write a string compare function using pointers and dynamic arrays, and am having trouble comparing the individual elements of the array contained with the struct. The code below...
5
by: plsHelpMe | last post by:
How to create dynamic javascript arrays using dojo toolkits Hello frens, I am in a big trouble. My objective is: I am having some categories shown by differnent radio buttons, on the click of...
6
by: robtyketto | last post by:
Greetings, Im a newbie to JSP/Javascript (unfortunalley). However I found enough example to create code that connects to my access db and populates two combo boxes. The selection of the...
5
by: judyw | last post by:
I am trying to build a form with many options depending on each other. I purchased a script called dynamic list options with which I create arrays of options that populate select boxes like this:...
2
by: selvialagar | last post by:
Let me tell my problem.There are list of parameters in a list box. User can select any number of Parameters (Maximum Limit is 10). Now I want to create dynamic arrays for all the 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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.