473,323 Members | 1,589 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Opera - Problem determening the selectedIndex via JavaScript/DOM

Hi there,

I have a problem determening the preselection of a dropdown list via
JavaScript DOM:
The followin code works fine with IE and Mozilla but does not preselect
the correct element in Opera:

//snip
myCurrentElement =
window.document.getElementById(''role'');
myNewElement =
window.document.getElementsByTagName(''font'')[0];
myNewChildElement =
window.document.getElementsByTagName(''select'')[0];

for (var i = 0; i < optionArray.length; i++)
{
myNewGrandChildElement =
window.document.createElement(''option'');
myNewGrandChildElement.setAttribute(''value'',
optionArray[i]["value"]);
if (optionArray[i]["selected"]!=null)
{

//myNewGrandChildElement.setAttribute(''selected'', ''selected'');
}
myNewGrandChildElementText =
window.document.createTextNode(optionArray[i]["label"]);

myNewGrandChildElement.appendChild(myNewGrandChild ElementText);
myNewChildElement.appendChild(myNewGrandChildEleme nt);
}
myNewElement.appendChild(myNewChildElement);
myCurrentElement.appendChild(myNewElement);
//snip

Regards
Reinhold Schrecker

Jun 7 '06 #1
2 3346


Reinhold Schrecker wrote:
myNewGrandChildElement =
window.document.createElement(''option'');

^^ ^^
That seems to be a syntax error.
Anyway, if you want to set the selected attribute of a newly created
option element then do e.g.
newOption.defaultSelected = newOption.selected = true;
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jun 7 '06 #2
Martin Honnen schrieb:
myNewGrandChildElement =
window.document.createElement(''option''); ^^ ^^
That seems to be a syntax error.
Anyway, if you want to set the selected attribute of a newly created
option element then do e.g.
newOption.defaultSelected = newOption.selected = true;
--

Martin Honnen
http://JavaScript.FAQTs.com/


Sorry, that was my mistake (I'm a newbie in this NG): The Code is
generated by PL/SQL, so I needed '' to get '.
Anyway, if you want to set the selected attribute of a newly created
option element then do e.g.
newOption.defaultSelected = newOption.selected = true;

Thanks Martin for your quick assistance, but defaultSelected does not
work either.

Meanwhile I have tried the following code (this time with correct
quoting):

//snip
myCurrentElement = window.document.getElementById('role');
myNewElement =
window.document.getElementsByTagName('font')[0];
myNewChildElement =
window.document.getElementsByTagName('select')[0];

for (var i = 0; i < optionArray.length; i++)
{
myNewGrandChildElement =
window.document.createElement('option');
myNewGrandChildElement.setAttribute('value',
optionArray[i]["value"]);
if (optionArray[i]["selected"]!=null)
{

//myNewGrandChildElement.setAttribute('selected', 'selected');
//myNewGrandChildElement.defaultSelected =
myNewGrandChildElement.selected = true;
myNewChildElement.selectedIndex = i;

}
myNewGrandChildElementText =
window.document.createTextNode(optionArray[i]["label"]);

myNewGrandChildElement.appendChild(myNewGrandChild ElementText);
myNewChildElement.appendChild(myNewGrandChildEleme nt);
}
myNewElement.appendChild(myNewChildElement);
myCurrentElement.appendChild(myNewElement);
window.document.close;
//snip

The funny thing is, that that Opera (V8.54) understands that code if I
replace "i" with a static number like 1, but it does not work with the
variable itself.

Regards
Reinhold

Jun 7 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Spijon | last post by:
Seems opera can not work normally with javascript, does anyone knows how to fix it? Thanks in advance.
10
by: tony kulik | last post by:
This code works fine in ie and opera but not at all in Mozilla. Anybody got a clue as to how to get it right? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <script...
3
by: % =joe % | last post by:
I cannot get this code to work. Very simple...I have three list menus. I want to do a check before the form submits to make sure that the value of the 3 fields is equal to 12. Here's my...
7
by: Jim Carlock | last post by:
Does a SELECT element (listbox) need to be inside a FORM element? The code I'm playing with: <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"...
1
by: VK | last post by:
Formally it may appertain to a CSS newsgroup, but from the other side it is *dynamic* plus it is JavaScript based. Anyway I had a customer who wanted cross-browser full-Aqua (Office XP style) so...
1
by: Grzegorz ¦lusarek | last post by:
Hi everyone. I'm looking for javascript tools for web browser like IE and OPERA. I want find something like javascript shell http://www.squarefree.com/shell/shell.html for IE and OPERA. Does anyone...
6
by: Jeremy | last post by:
I really want to make my scripts work in Opera. I really, really do. But it seems like an uphill struggle. First of all, I can't get ANY kind of debug output. No error messages in the...
2
by: swissreporter | last post by:
Hi - I have a really stupid failure of code, can't figure it out. Two fields in a form, Textinput and select; if text is written into input, select changes "selected" to a matching option. This...
4
by: ramchml | last post by:
i have two select boxes.based on the selected value in one select box it show the maximum options in the other select box in next page.i used javascript onclick function.for first time it shows...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.