[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Opera javascript problem with dynamically adding options to a select

Posted on 2005-04-20
9
Medium Priority
?
649 Views
Last Modified: 2008-01-16
Have a problem in Opera 8 beta. Showing up in adding Option objects to a Select object 's options array. It seems to be adding it successfully to the array, however at the end , I get a options.length of 0. The same code works perfectly in IE 6 (XP), and Firefox 1.0 (XP and Mac). Have an another problem in the way of checking for this on Safari..

I can't see why this wouldn't work. Everything else works in Opera apart from this (ie when I generate options as html). The only thing I can think that I might try is to use the Node approach with a createChild / appendChild method (my brain is too wasted to look up the syntax) or just load Opera 7 and see if it is a beta problem.

I'd appreciate someone else having a look at this.

Test code. listPaneName and selectName are just id's. dataArr is a new Array with a simple set of strings appended. Selected is a string of the currently selected value in dataArr.

function LoadSelectionSimple(listPaneName, selectName, dataArr, selected)
{
      var rightpane = top.frames["RightPane"];
      if (rightpane != null)
      {
            var listpane = rightpane.frames[listPaneName];
            if (listpane != null)
            {
                  var selection = listpane.document.getElementById(selectName);
                  if (selection != null)
                  {
                        if (dataArr == null)
                              alert('LoadSelectionSimple: dataArr is null');
                        else if (dataArr.length == 0)
                              alert('LoadSelectionSimple: dataArr is empty');
                        else
                        {
                        try
                        {
                              for (i = 0; i < dataArr.length; i++)
                              {
                                    var str = "";
                                    var line = dataArr[i];
                                    var isselected = false;
                                    if (selected != null && line == selected)
                                          isselected = true;
                                    selection.options[selection.options.length]
                                          = new Option(line, line, isselected, isselected);
                              }
                        }
                        catch(e)
                        {
                              alert('oops-' + e);
                        }
                        alert(selection.options.length);
                        }
                  }
                  else
                        alert('LoadSelectionSimple: no selection');
            }
            else
                  alert('LoadSelectionSimple: no listPane');
      }
      else
            alert('LoadSelectionSimple: no rightPane');
};
0
Comment
Question by:smartsims
8 Comments
 
LVL 25

Expert Comment

by:archrajan
ID: 13825065
I just downloaded opera 8
and tried some code which adds options to select box dynamicalluy... it works fine and thats not  a problem with opera...

0
 

Author Comment

by:smartsims
ID: 13825535
Interesting... did you add using the Select.options[] or using another method...
Currently I just keep getting more puzzled, the options array is present, and has the right kind of data type:- OptionsHTMLCollection. Either I'm managing to add to an implicit copy or there is an object going AWOL
0
 
LVL 25

Accepted Solution

by:
archrajan earned 1000 total points
ID: 13825556
here my syntax:
var sel = document.formname.selectboxname
var opt = new Option("javascript","javascript","javascript");
sel.options[sel.length] = opt;

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 75

Assisted Solution

by:Michel Plungjan
Michel Plungjan earned 1000 total points
ID: 13825690
If you run into problems with that, then try

var sel = document.formname.selectboxname
sel.options.length++
sel.options[sel.options.length-1] = new Option("javascript","javascript","javascript");

that is anyway a fix for an older IE problem
0
 

Author Comment

by:smartsims
ID: 13826002
Ummm - well you helped prove that I'm actually talking to the correct object... The visible object drop down increased from the single HTML option saying 'Junk' with the following code, to having two rows. But the new one had blank text.

                  try
                  {
                  var sel = listpane.document.getElementById("ListFilter");
//                  sel.options[sel.options.length] = new Option("javascript","javascript");
                  sel.options.length++;
                  sel.options[sel.options.length-1] = new Option("javascript","javascript");
                  }
                  catch(e)
                  {
                        alert('oops-' + e);
                  }

The only other thing I can think of is that I'm calling from one frame to another. The ListPane frame body has a onload=LoadSelectionSimple(listPaneName,....)

I wonder if it isn't accepting a new object created in one frame being added to a collection from another frame. Or that I don't have that Select in a Form...

Anyway dawn is approaching - time for bed...
0
 

Author Comment

by:smartsims
ID: 13826019
Time to ratchet up the points
0
 
LVL 25

Expert Comment

by:archrajan
ID: 13826024
U have ur site accessible online?
if not post ur view sourcE?
0
 
LVL 17

Expert Comment

by:Cem Türk
ID: 15641132
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I will leave the following recommendation for this question in the Cleanup topic area:
    Split: archrajan & mplungjan

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

cem_turk
EE Cleanup Volunteer

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question