[Javascript] adding Option to an opener.form.select

David T. Lovering dlovering at gazos.com
Tue Mar 25 09:34:58 CST 2003


Ugh!  Cold-Fusion (even the latest and greatest version) is a poor substitute for good solid PHP, Java, and JavaScript coding.  Its features are chaotic, non-orthogonal, and integrate very poorly with other packages, and have all sorts of inheritance
issues which will drive you mad eventually.  [And let us not forget that it is God-awful slow, has huge latency problems, and sucks screen and CPU resources]. The only people who like it are newbies who think they only have to learn one "language" to make
everything they want done happen without any downsides.
Enough ranting.

The method I use for adding to a pre-existing select widget is as follows --

  var myMenu = document.forms[0].mySelect;
  myMenu.options[myMenu.length] = new Option("bogus", "bogus-value");
  
Obviously, you can insert the other two Option parameters if you wish [the third controls the default selection, and the fourth determines whether this item is selected for the moment], but I usually leave that to my 'init' routine to work out.

Although the DOM model certainly encourages you to believe that the universal constructor assignments are 100% viable, I've had problems with them, particularly in computing environments with diverse browsers, OS's, and such like.  You are welcome to try
them of course (and many are very useful), but be sure to vet them for all the platforms you expect to have exercising your code.

-- Dave Lovering




Terry wrote:
code
-------------------------------------------
newOption = new Option(optTxt, optVal, 0, 1);
opener.#attributes.formName#.#attributes.elem#[opener.#attributes.formName#.#attributes.elem#.length] = newOption;


ok, able to read values from the opener.form.select using the same syntax as above but i cannot seem to add a new option...  

btw, the ## are CF variables, just assume that attributes.formName is the name of the form from opener and attributes.elem is the name of the select object......

comments??


~ Terry
757 581-5981
AIM/Yahoo: lv2bounce


More information about the Javascript mailing list