Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

! Problem with <SELECT> ! SOS

Status
Not open for further replies.

Jay1Roy

Programmer
Jul 10, 2001
95
0
0
IE
Hi,

I am having serious problem with <SELECT> in my JavaScript.

optn = new Option(&quot;Inserting new Option...&quot;);
parent.upFrm.document.form.selc.options[0]=optn;

The above two lines are suppose to insert a new option in a drop down list named selc within form named 'form'. This works perfect with IE6.0 but gives all kind of errors with IE5.0!!! I need this to work somehow on IE5.0 by tomorrow. PLEASE SOME ONE HELP!!! SOS SOS...

Thanks a million for a solution (in advance)

Jayanta. :-(

user.gif
 
Just a few thoughts.

Change your form name. I think the word form is a reserved word in JavaScript.

You might try storing the Option values and Text to variables and issue the statement a little differently. Something like this.
Code:
value = &quot;1&quot;
text = &quot;Option 1&quot;
parent.upFrm.document.formname.selc.options[0] = new Option(text,value)

Make sure you're not overwriting options using the new Option() method. To prevent this, you either need to add an option to the end of the list like this.
Code:
listobj.options[listobj.options.length] = new Option()
Since the index is zero based and the length is 1 based, the length should equal the new index number.

Or if you're generating a new list, set the options to zero first.
Code:
listobj.options.length = 0
Then add your new options starting with options[0].

ToddWW
 
This work with IE 4.0 :

<SELECT NAME=&quot;select&quot;>
</SELECT>
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
<!--
optn = new Option(&quot;new option&quot;)
document.all.select.options[0] = optn
//-->
</SCRIPT>

I think your problem is with parent.upFrm.document.

I hope this helps you
X-) Split.
 
Give the form that the select box is in a Name then substitute 'form' in the following statement with your new form name

parent.upFrm.document.form.selc.options[0]=optn

Not sure you need the parent.upFrm unless you are in a frame and you are referencing the select box in a nother frame.

Also you nee to pass in an option value, so write

optn = new Option(&quot;Inserting new Option...&quot;,&quot;Option Value&quot;);

Replacing &quot;Option Value&quot; with the required value
 
Jayanta,

That shouldn't be a problem. You should definitely be able to add options to a select list in another frame. The answer's in there somewhere, just keep digging or maybe post the error back here.

By the way you displayed your original question, I'm guessing that you're page is doing alot more than just adding a single option..

ToddWW
 
I should have been more clear. Let me show you what.
----------------------------------------
Frame 1 with a Form named FN has a drop down list.
----------------------------------------
Frame 2 got a table, when a row is clicked, it shoud be added in the existing list up there in frame 1.
----------------------------------------
My actual code reads this. (this is just a piece out)
Code:
optn = new Option(ae[a].rowData[0]+ae[a].rowData[1]+ae[a].rowData[2],&quot;1&quot;);

parent.upFrm.document.FN.selAcc.options[pos++]=optn;


It works FINE in IE6.0 but gives error like &quot;object dosent support this property&quot; !!!

I can see the sword hanging on me! Some 1 got to help! SOS

SOS SMS!
user.gif
 
The Code I listed works fine with IE6.0 but fails with IE5.0

I need my code to run on IE5.0...
user.gif
 
Do you know which portion of the code is failing. Try this.
Code:
optn = new Option(ae[a].rowData[0]+ae[a].rowData[1]+ae[a].rowData[2],&quot;1&quot;);
window.alert(ae[a].rowData[0]+ae[a].rowData[1]+ae[a].rowData[2])
window.alert(pos++)
//parent.upFrm.document.FN.selAcc.options[pos++]=optn;

Do you get the data you expect in the alert windows, or are you getting errors on those ??

ToddWW
 
Yeah, these two statements work fine...

parent.upFrm.document.FN.selAcc.options[pos++]=optn;
IE5.0 Yells at this line, &quot;Object dosen't support this property or method&quot;!! :-(
user.gif
 
Why not try pass the values to a script on the Select box page and get the script to add the option to the select rather than trying to do it from another page
 
If I were troubleshooting this, I would try this first. Just to make sure that we're not over looking the ability to add an option from one frame to another.
Code:
parent.upFrm.document.FN.selAcc.options[parent.upFrm.document.FN.selAcc.length] = new Option(&quot;Option 1&quot;,&quot;1&quot;)
If that works, then I would try this.
Code:
optn = ae[a].rowData[0]+ae[a].rowData[1]+ae[a].rowData[2]
parent.upFrm.document.FN.selAcc.options[parent.upFrm.document.FN.selAcc.length] = new Option(optn,&quot;1&quot;)
I'm not sure what your pos++ is doing, but the examples I've provided above will add the option to the end.

ToddWW
 
Well sjravee,

Accessing it isn't a problem. Its not working the method. Still I tried your suggestion (actually I would try any thing to make it work!) but in vain... am sorry.

optn= document.createElement(&quot;Testing&quot;);
document.FN.selAcc.add(optn,0);

these two lines... in the same file gives an error &quot;Invalid Argument&quot;!! samething is happening in the original location as well...
user.gif
 
Perceverience pays... Ha..! finally, I could make it move the way I wanted... thank you all very much for helping. I put the code in to the upper frame and accessed the tables data from there
Code:
document.FN.selAcc.options[pos++]=new Option(ae[i].rowData[0]+ae[i].rowData[1]+ae[i].rowData[2]);

worked fine there which was messing in the lower frame... this is still not clear to me why it didnt work in there?

I had the this code and other codes in the main frame set the parent HTML document which defined the frameset and stuff.

let me know the exact reason of it not working there and working here...

Thanx all for trying to help...Sjravee thanks for the suggestion.

:)

Jayanta.
user.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top