469,330 Members | 1,379 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,330 developers. It's quick & easy.

Select.appendChild(Option) doesnt work in IE

I am trying to set the value for a select list..the code is as below...It works fine in firefox, but dosent work in IE ...need urgent help ...

__________________________________________________ _______________
Expand|Select|Wrap|Line Numbers
  1. var Name="<%=value%>";
  2.  
  3.  
  4.            var oForm = parent.window.opener.document.mainForm;
  5.             var oSelect = oForm.elements["users1"];
  6.             var oOptions = oSelect.options;
  7.             var bAdd = true;
  8.             if (oOptions) {
  9.                 for (var i=0; i < oOptions.length; i++) {
  10.                     if (oOptions[i].value == Name) {
  11.                         bAdd = false;
  12.                     }
  13.                 }
  14.             }
  15.             if (bAdd) {
  16.                 var oOption = document.createElement("OPTION");
  17.                 oOption.setAttribute("value", Name);
  18.                 oOption.appendChild(document.createTextNode(Name));
  19.                 oSelect.appendChild(oOption);
  20.             }
  21.  
__________________________________________________ _______________
I tried using this code which I find in some other site, but this also didnt work

Expand|Select|Wrap|Line Numbers
  1. if (document.all) { // IE
  2.                 select.add(opt);
  3.             }
  4.             else {
  5.                 select.appendChild(opt);
  6.             }
  7.  
need urgent help ..thanks in advance
Nov 27 '07 #1
2 8092
mrhoo
428 256MB
IE up to 6 doesn't know about option childNodes.
Set the option's text property instead- it works in more modern browsers as well.

oOption.text=Name;
Nov 27 '07 #2
mrhoo
428 256MB
IE up to 6 doesn't know about option childNodes.
The option gets added to the select, but it has no text content.


Set the option's text property instead- it works in more modern browsers as well.

Option.text=Name;
Nov 27 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Michael Hoffmann | last post: by
4 posts views Thread by Jeff Anderson | last post: by
11 posts views Thread by Stefan Finzel | last post: by
2 posts views Thread by shagy | last post: by
1 post views Thread by kirke | last post: by
1 post views Thread by aamirghanchi | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Purva khokhar | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.