473,287 Members | 2,682 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,287 software developers and data experts.

remove select option on Pocket IE

Hi

trying to remove one or all elements of select options fails for Pocket
Internet Explorer. Is there a way to do this?

if is_PIE {
// this does not work on Pocket IE
while (opt.length) {
opt.remove(0);
}
} else {
# IE 5.+, Moz, FF, Galeon, Opera, Konq
# remove everything at once
opt.length = 0;
}
TIA

Stefan
Oct 2 '05 #1
11 2982


He he, nevermind IE pocket, that code is completely invalid, shouldn't work
for any IE at all. document.YOURFORMNAME.YOURSELECTNAME.options[0]=null
removes 1st option and so on and so on.
Danny
Oct 3 '05 #2
Danny wrote:

He he, nevermind IE pocket, that code is completely invalid, shouldn't work
for any IE at all.
Posting non-sensical replies to nothing at all can only be interpretted
as an attempt to confuse.

Presumably you think the 'else' part of the posted code is in error, but
you are wrong.

document.forms[formname].elements[selectname].options.length = 0;

removes all of a select's options in one go - just as the OP indicated.
for any IE at all. document.YOURFORMNAME.YOURSELECTNAME.options[0]=null
removes 1st option and so on and so on.


--
Rob
Oct 3 '05 #3
Stefan Finzel wrote:
Hi

trying to remove one or all elements of select options fails for Pocket
Internet Explorer. Is there a way to do this?

if is_PIE {
// this does not work on Pocket IE
while (opt.length) {
opt.remove(0);


I don't have pocket IE to play with, but that syntax works fine in IE
and Firefox. Have you tried looping through the options collection and
setting each option to 'null?

var i = opt.length;
while ( i-- ){
opt[1] = null;
}

or

while ( opt[0] ){
opt[0] = null;
}
or using the removeChild method?

var i = opt.length;
while ( i-- ){
opt[i].parentNode.removeChild(opt[i]);
}

or

var sel = opt[0].parentNode;
while ( sel.firstChild ){
sel.removeChild(sel.childNodes[0]);
}

or some combination of the above?
[...]

--
Rob
Oct 3 '05 #4
Stefan Finzel wrote:
Hi

trying to remove one or all elements of select options fails for Pocket
Internet Explorer. Is there a way to do this?

if is_PIE {
I'll see if I can get it right this time! You shouldn't be browser
sniffing, so 'is_PIE' should not be required at all.

// this does not work on Pocket IE
while (opt.length) {
opt.remove(0);
I guess from your code that 'opt' is the options collection, but the
remove method belongs to the select element, so it can't be expected
to work. If you get the select element, then:

while (sel.options.length){
sel.remove(0);
}

will remove all the options in DOM 1 compliant browsers, including all
those listed below - hence no need for browser sniffing.
}
} else {
# IE 5.+, Moz, FF, Galeon, Opera, Konq
# remove everything at once
opt.length = 0;
}


Yes, that is convenient and possibly quicker, but unless you have 100
or so options it will be undetectably so. And having a select with
100 options on a PDA does not sound like a good idea in the first place.

Here's a small test case:

<form action="">
<select>
<option>opt 1
<option>opt 2
<option>opt 3
</select>
<input type="button" value="remove options" onclick="
var sel = this.form.elements[0];
while (sel.options.length){
sel.remove(0);
}
">
</form>
--
Rob
Oct 3 '05 #5
Argh!!! That's it! Thank you very much RobG.

RobG wrote:
....
I guess from your code that 'opt' is the options collection, but the
remove method belongs to the select element, so it can't be expected to
work. If you get the select element, then:
while (sel.options.length){
sel.remove(0);
}
....

Yes, that is convenient and possibly quicker, but unless you have 100 or
so options it will be undetectably so. And having a select with 100
options on a PDA does not sound like a good idea in the first place.

....
And that's really the initial problem, avoiding users to get large
selects while porting an javascript free application to small screen
devices.
To shorten selects i try using hierarchical selects and data in arrays
by removing and adding options.

Now removing works. But adding is still a problem too. Please see

(opts is the select element, data is a array, lnk is
another select element)

for (var i = 0; i < data.length; i++) {
if (is_PIE) {
// while this completly works on IE5.+,
it fails // in the next line on Pocket IE
var el = document.createElement("OPTION");

opts.add(el,i);
el.innerText = data[i];
el.value = lnk.value + "_" + data[i];
} else {
opts.options[i] = new Option(data[i], lnk.value
+ "_" + data[i]);
}
}

Any idea what's wrong with my usage of document.createElement("OPTION")
on Pocket IE?

TIA

Stefan
Oct 3 '05 #6
Stefan Finzel wrote:
Argh!!! That's it! Thank you very much RobG.

RobG wrote:
...
I guess from your code that 'opt' is the options collection, but the
remove method belongs to the select element, so it can't be expected
to work. If you get the select element, then:
while (sel.options.length){
sel.remove(0);
}
...

Yes, that is convenient and possibly quicker, but unless you have 100
or so options it will be undetectably so. And having a select with
100 options on a PDA does not sound like a good idea in the first place.


...
And that's really the initial problem, avoiding users to get large
selects while porting an javascript free application to small screen
devices.
To shorten selects i try using hierarchical selects and data in arrays
by removing and adding options.

Now removing works. But adding is still a problem too. Please see


For the sake of readability, I've re-posted your code below. Please
indent using two or four spaces and manually wrap code at about 70
characters.

(opts is the select element, data is a array, lnk is
another select element)

for (var i = 0; i < data.length; i++) {
if (is_PIE) {
You really should get rid of browser sniffing, what works in Pocket IE
will probably work elsewhere too.
// while this completly works on IE5.+, it fails
// in the next line on Pocket IE
var el = document.createElement("OPTION");
I think IE in general has problems with options, why don't you just use
the code below what uses new Option? There doesn't seem to be anything
wrong with the code to this point.

opts.add(el,i);
el.innerText = data[i];
el.value = lnk.value + "_" + data[i];
That appears to be straight from the MS documentation, the use of
innerText will trouble many browsers.

You said that 'lnk' is another select. In some browsers, lnk.value will
work, but a more robust solution is:

el.value = lnk[lnk.selectedIndex].value + "_" + data[i];
} else {
opts.options[i] = new Option(data[i], lnk.value + "_" + data[i]);
opts.options[i] = new Option( data[i],
lnk[lnk.selectedIndex].value
+ "_" + data[i]);
}
}

Any idea what's wrong with my usage of document.createElement("OPTION")
on Pocket IE?


No. Try using just the new Option bit - it works in just about all
browsers and gets rid of the IE-centric innerText bit.

Hope that helps... :-)

--
Rob
Oct 3 '05 #7
RobG wrote:
....
You really should get rid of browser sniffing, what works in Pocket IE
will probably work elsewhere too. ....

Yes, you are absolutly right! I don't like it either. But first I try to
get a working application and then can get rid of each of such browser
sniffing. Don't like to change the code for other browsers to avoid
getting lost before it's done.

.... I think IE in general has problems with options, why don't you just use
the code below what uses new Option? There doesn't seem to be anything
wrong with the code to this point. ....

Well, using new Option didn't work at all for Pocket IE. That's the
reason I am trying to find any workaround. Both code snippets work on IE
5.+.

Debuging with alert boxes I found the Pocket IE stops working at

var el = document.createElement("OPTION");
opts.add(el,i);
el.innerText = data[i];
el.value = lnk.value + "_" + data[i];


That appears to be straight from the MS documentation, the use of
innerText will trouble many browsers.

You said that 'lnk' is another select. In some browsers, lnk.value will
work, but a more robust solution is:

el.value = lnk[lnk.selectedIndex].value + "_" + data[i];


That's a nice hint. I'll take it. Thank you RobG.

Stefan
Oct 3 '05 #8
Stefan Finzel wrote:
RobG wrote:
...
You really should get rid of browser sniffing, what works in Pocket IE
will probably work elsewhere too.


...

Yes, you are absolutly right! I don't like it either. But first I try to
get a working application and then can get rid of each of such browser
sniffing. Don't like to change the code for other browsers to avoid
getting lost before it's done.

...
I think IE in general has problems with options, why don't you just
use the code below what uses new Option? There doesn't seem to be
anything wrong with the code to this point.


You have one possibility left: clone an existing option element, modify
its attributes and add that. Something like:
var newOpt = sel.options[0].cloneNode(true);
newOpt.value = 'someValue';
newOpt.text = 'someText';
sel.appendChild(newOpt);

Again, this works in everything I tried, but I can't test Pocket IE.
Here's hoping.
I've played a bit with innerHTML but it doesn't seem to work at all for
this, so it isn't an option (it would have been a pretty bad option anyway).
[...]
--
Rob
Oct 3 '05 #9
Well after playing around with your and several other ideas, I found a
working solution (tested on Windows Mobile 2003 SE Internet Explorer).

if (is_PIE) {
// Pocket IE: do not use xxx.selectedIndex, it fails only here!?
var opt = new Option(data[i], lnk.value + "_" + data[i]);
// Pocket IE: do not use xxx.options[...]=...
opts.add(opt,i);
} else {
// all other: IE 5.+/6.+, Moz, NS, FF, Galeon, Opera, Konq
opts.options[i] = new Option(data[i], lnk[lnk.selectedIndex].value\
+ "_" + data[i])
}

Large option collections are kept small now by dynamically removing and
adding options in cascaded select.

Thank you RobG
Oct 5 '05 #10
Stefan Finzel wrote:
Well after playing around with your and several other ideas, I found a
working solution (tested on Windows Mobile 2003 SE Internet Explorer).

if (is_PIE) {
// Pocket IE: do not use xxx.selectedIndex, it fails only here!?
var opt = new Option(data[i], lnk.value + "_" + data[i]);
// Pocket IE: do not use xxx.options[...]=...
opts.add(opt,i);
} else {
// all other: IE 5.+/6.+, Moz, NS, FF, Galeon, Opera, Konq
opts.options[i] = new Option(data[i], lnk[lnk.selectedIndex].value\
+ "_" + data[i])
}
That amazing. So 'new Option' works, you just have to create the option
first, then add it to the select.

Large option collections are kept small now by dynamically removing and
adding options in cascaded select.

Thank you RobG


Hey, that's great.

I'd expect that the 'is_PIE' method will work in all other browsers too,
it's in DOM 1, so it *should* be ubiquitous (of course, that doesn't
mean that it is).

--
Rob
Oct 5 '05 #11
....
I'd expect that the 'is_PIE' method will work in all other browsers too,
it's in DOM 1, so it *should* be ubiquitous (of course, that doesn't
mean that it is).

....

Well, hope so, too. There are a few other things I want to modify to
work on Pocket IE first, like a calendar, a mac/ip address input and
maybe a sortable table. After that I'll go to test all of this with
different browsers again and kick off all unnecessary browser sniffing
once again. Currently only four special cases are left, all for Pocket IE.

I'll "(tell my experience|cry for help)" here again.
Oct 6 '05 #12

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

Similar topics

2
by: Ramamoorthy Ramasamy | last post by:
Hi all, I would like to create a page with VBscript and ASP which will contain two list-boxes one in the left side and the other in the right side with two buttons namely "Add>>" and "<<Remove"...
3
by: Rob | last post by:
Hi, I've got a small javascript problem and I'm kinda stuck. I'm using classic ASP. I have a select box which is populated by a database query and there is a buttom that when clicked it will move...
8
by: rkrishna | last post by:
I have an issue that I am trying to solve. I have three select lists (supposed to be preference 1, 2,3) and each of them have the same three options. As soon as I select one of the choices from...
8
by: Mikey | last post by:
I have an XML document as follows: <Menu> <Group> <Item Text="About Us" AccessRoles="All"> <Group> <Item Text="Option 1" AccessRoles="All" /> <Item Text="Option 2" AccessRoles="All" /> <Item...
0
by: deepak | last post by:
i have set multiple selection property in bith listboxes(html control) to true. i have taken 2 buttons(html control) say Button1,Button2.now i want to add mutiple selected items to another listbox...
3
by: Beholder | last post by:
I hope that someone can help me with the following: Short background explenation: I have a shrfepoint page (newform.aspx) in a item list. On this page is a lookup column that displays a lookup...
7
chunk1978
by: chunk1978 | last post by:
hello. so i have 2 select menus which add and remove options from a 3rd select menu... it seems, however, that it's not possible to use different select menus to toggle a 3rd, because when an...
11
by: Richard Maher | last post by:
Hi, I have read many of the copius entries on the subject of IE performance (or the lack thereof) when populating Select Lists. I don't mind the insert performance so much, (I get 100x120byte...
0
by: ClassicNancy | last post by:
If I want to remove the drop down for the year will that make the birthday not show on the calendar? If it looks like it is ok to remove it what can be removed?? What should it look like? ...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
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
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
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: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

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.