By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,741 Members | 2,004 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,741 IT Pros & Developers. It's quick & easy.

Looping to populate selections for IE & Firefox

P: n/a
<script>

function filldims()
{
var objSelect = document.getElementById("id_intwidth");
objSelect.options.length = 0;

for(var i = 20; i < 31; i++)
{
var objOption = document.createElement("option");
objOption.text = i;
objOption.value = i;

//the following line WORKS IN FIREFOX ONLY
objSelect.add(objOption,
objSelect.options[objSelect.options.length]);
};
}

</script>
Nov 3 '08 #1
Share this Question
Share on Google+
9 Replies


P: n/a
Rick W. wrote:
//the following line WORKS IN FIREFOX ONLY
objSelect.add(objOption,
objSelect.options[objSelect.options.length]);
That is incorrect. It works in all user agents that have the object
referred to by `objSelect' implement the HTMLSelectElement interface
of W3C DOM Level 2 HTML. However, it should be noted that passing
`null' for the second argument suffices here:

<http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-14493106>
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Nov 3 '08 #2

P: n/a
I added the 'null' but it still didn't work.
but if you look closer I AM passing two parameters already.

In IE, I do get a list of blank items.
another words, the list is now 10 items long, but the list has blank
values in it.

Rick
Nov 3 '08 #3

P: n/a
Rick W. wrote:
I added the 'null' but it still didn't work.
Nobody said anything about *adding* `null'. I suggested you should
*replace* the second argument with `null' because it is more efficient (and
less error-prone) than retrieving an (obviously) non-existing reference
through a property access.
but if you look closer I AM passing two parameters already.
If you look closer, nobody debated that in the first place.
In IE, I do get a list of blank items. another words, the list is now 10
items long, but the list has blank values in it.
Nobody debated that IE does not implement the HTMLSelectElement interface
for its Select objects either.

Since apparently you don't see the problem, I would like to point out to you
that your posting completely lacks a question.

Please read the FAQ carefully: <http://jibbering.com/faq/>

And it wouldn't hurt to post under your full name, Rick W. #4711.
PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Nov 3 '08 #4

P: n/a
Hi Rick,
//the following line WORKS IN FIREFOX ONLY
Might not be of any use to you, but I use this sort of thing: -

queList = document.queOptions.queList;
: : :
queList.length = zeros;
queList.options[queList.length] = new Option (msgQue, msgQue);
OR
selectRef = document.getJobs.jobList;
selectClone = selectRef.cloneNode(true);
: : :
selectRef.size = 1;
swapClone = selectClone.cloneNode(true);
selectRef.parentNode.replaceChild(swapClone, selectRef);
selectRef = document.getJobs.jobList;
: : :
selectRef.options[selectRef.options.length] = new Option (jobMsg,
jobMsg);

For complete example code please see: -
http://manson.vistech.net/t3$examples/demo_client_web.html

Username: TIER3_DEMO
Password: QUEUE

Enter "*" asterix for the Queue Name and then hit "Get Job Info"

All source can be found at: -
http://manson.vistech.net/t3$examples/

Cheers Richard Maher

"Rick W." <Ri*******@sbcglobal.netwrote in message
news:c5**********************************@e1g2000p ra.googlegroups.com...
<script>

function filldims()
{
var objSelect = document.getElementById("id_intwidth");
objSelect.options.length = 0;

for(var i = 20; i < 31; i++)
{
var objOption = document.createElement("option");
objOption.text = i;
objOption.value = i;

//the following line WORKS IN FIREFOX ONLY
objSelect.add(objOption,
objSelect.options[objSelect.options.length]);
};
}

</script>

Nov 3 '08 #5

P: n/a
SAM
Le 11/3/08 8:53 PM, Rick W. a écrit :
<script>

function filldims()
{
var objSelect = document.getElementById("id_intwidth");
objSelect.options.length = 0;

for(var i = 20; i < 31; i++)
{
var objOption = document.createElement("option");
objOption.text = i;
objOption.value = i;

//the following line WORKS IN FIREFOX ONLY
objSelect.add(objOption,
objSelect.options[objSelect.options.length]);
objSelect.appendChild(objOption); // would have to work
>
};
}

function filldims()
{
var objSelect = document.getElementById("id_intwidth");
objSelect.options.length = 0;

for(var i = 20; i < 31; i++)
{
objSelect.options[objSelect.options.length] = new Option(i,i);
}
}
</script>
Nov 3 '08 #6

P: n/a
Mon, 3 Nov 2008 11:53:26 -0800 (PST), /Rick W./:
function filldims()
{
var objSelect = document.getElementById("id_intwidth");
objSelect.options.length = 0;

for(var i = 20; i < 31; i++)
{
var objOption = document.createElement("option");
objOption.text = i;
objOption.value = i;

//the following line WORKS IN FIREFOX ONLY
objSelect.add(objOption,
objSelect.options[objSelect.options.length]);
The line actually works in all standard-compliant [1] browsers, but
Internet Explorer (as already pointed out in another reply). Try
using just:

objSelect.add(objOption);

IE versions prior 8 expect an optional index [2] and not an object
reference as a second argument.
>
};
}
[1] http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-14493106
[2] http://msdn.microsoft.com/library/ms...us,VS.85).aspx

--
Stanimir
Nov 3 '08 #7

P: n/a
Stanimir Stamenkov wrote:
Mon, 3 Nov 2008 11:53:26 -0800 (PST), /Rick W./:
> //the following line WORKS IN FIREFOX ONLY
objSelect.add(objOption,
objSelect.options[objSelect.options.length]);

The line actually works in all standard-compliant [1] browsers, but
Internet Explorer (as already pointed out in another reply). Try
using just:

objSelect.add(objOption);
Bad advice. The second argument of HTMLSelectElement::add() is mandatory;
with the call above you are risking an exception along the lines of "not
enough arguments".
IE versions prior 8 expect an optional index [2] and not an object
reference as a second argument.
So it would appear to be a viable approach, unless MSHTML < 8 throws
exceptions then, to pass `null' for the second argument, check the `value'
or `text' of the newly added item, and modify its `value' and `text'
properties when necessary.

However, there is also a well-documented proprietary, but apparently
cross-browser approach (originating from "DOM Level 0"):

var opts = sel.options;
opts[opts.length] =
new Option("text", "value, defaultSelected, selected);

whereas the second argument is optional, and `defaultSelected' and
`selected' are optional boolean values that have the meaning of their
identifiers.
PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Nov 4 '08 #8

P: n/a
Thank you SAM
Your solution appears to work fine in both browsers.

I'm going to go with it.
Hopefully there are no hidden issues with this approach that I
inevitably find out later.

Thanks again,
Rick
Nov 4 '08 #9

P: n/a
Rick W. wrote:
Thank you SAM
Your solution appears to work fine in both browsers.
IE 6 and IE 7, I presume ...

To learn you have a lot, young apprentice.
PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f8*******************@news.demon.co.uk>
Nov 4 '08 #10

This discussion thread is closed

Replies have been disabled for this discussion.