[Javascript] dynamic forms - HELP

Varsou Nilsa nvarsou at infoserve.gr
Thu Mar 29 01:08:35 CST 2001


I have done something identically, here's what I did to force the new
option to be selected...

MyListBox = window.document.forms[0].ListBoxName;
for(var i = 0; i < MyListBox.options.length; i++) {
if (MyListBox.options[i] != null)
MyListBox.options[i].selected = true;
}
if (MyListBox.value == '')
{
MyListBox.options[0] = new Option("New Option 1");
MyListBox.options[0].selected = true;
}

-----Original Message-----
From: Seth Northrop [mailto:seth at calculon.northrops.com]
Sent: Wednesday, March 28, 2001 10:40 PM
To: javascript at LaTech.edu
Subject: [Javascript] dynamic forms - HELP



I'm getting desperate!  :)

The only thing I was to happen is to pop up a window with a form, and,
have that form result in a population of a select menu.  The text box
will
result in what's seen by the user.  The value of that element will be
dynamically generated by a backend script and built into the
javascript.  The only snag to this equation is that some variable names
have [ ]'s in their names (which is a reserved character in javascript.

This is what I have:

<html>
<head>
<Script Language = "Javascript" Type="Text/Javascript">

<!--  Hide script from older browsers
 pWin = window.opener;
 pOpt = pWin.document.formName.elements["step_spec_nameID"].options;
 pOpt[pOpt.length] = new Option('This is a test', 5652023, true, true);
 window.close();
// -->

</script>
</head>

In Netscape it works with ONE exception.  Although the value APPEARS to
be
selected once it's dynamically added, if the user doesn't actually TOUCH
the pull down (ie, REselect the value) it will submit the form with the
value of the element that was selected BEFORE the new value was added.  
So, I need to either FORCE it to select the new value (and submit with
that value without intervention) OR NOT have it selected so the user
will
think to select it manually.

In IE it doesn't work AT ALL!  It just dumps the above code and doesn't
update the pull down OR execute the window.close();  I presume there is
a
javascript parse error in there.. but, IE doesn't seem to indicate that.

Ugh!  This one little javascript UI issue is holding back a rather huge
project (nearly 50k of backend programming).  

Can anyone help?


_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
http://www.LaTech.edu/mailman/listinfo/javascript




More information about the Javascript mailing list