473,387 Members | 1,812 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,387 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 2990


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? ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.