473,714 Members | 2,395 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3024


He he, nevermind IE pocket, that code is completely invalid, shouldn't work
for any IE at all. document.YOURFO RMNAME.YOURSELE CTNAME.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.YOURFO RMNAME.YOURSELE CTNAME.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.rem oveChild(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.le ngth){
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.eleme nts[0];
while (sel.options.le ngth){
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.le ngth){
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.create Element("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.create Element("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.le ngth){
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.create Element("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.selectedInd ex].value + "_" + data[i];
} else {
opts.options[i] = new Option(data[i], lnk.value + "_" + data[i]);
opts.options[i] = new Option( data[i],
lnk[lnk.selectedInd ex].value
+ "_" + data[i]);
}
}

Any idea what's wrong with my usage of document.create Element("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.create Element("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.selectedInd ex].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.selectedInd ex, 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.selectedInd ex].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

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

Similar topics

2
3055
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" so that if the user selects a value listed in the left side list-box and presses "Add>>" then that selected value should go inside the right side list-box. Similarly if the user selects a value listed in the right side list-box and after clicking...
3
2348
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 the selected item from the first select box and move it to another select box: document.form2.list.options = new Option(count + 1 + ". " + name,company); Then I want to remove it from the first select box:
8
2294
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 list1, i would like to remove it from the options of list 2 and so on for list 3. So effectively, List 2 has two choices and List3 only has one choice that can be made. Any pointers on how to accomplish this?
8
2636
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 Text="Option 3" AccessRoles="All" /> </Group>
0
1467
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 after clicking button1, and similray remvoing the mutiple selected ite,s from, another after clicking button2 ,, how can i do this ,, my script is given belo...
3
6437
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 of all category items in previous items. In the code this results in a select/options list like this: <SELECT TABINDEX=1 NAME="urn:schemas-microsoft-com:office:office#CatLookup"><OPTION
7
16885
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 options is removed, the list's options switch, making written javascript unusable? the following code is an example: <script type="text/javascript"> function ToggleEmail()
11
4507
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 rows inserted/sec up to 500, and 100rows/6secs up to 3000, which isn't great but then the Row Count is clicking away for the user to see and they can hit the "cancel" button at anytime, so overall I'm happy), what really disappoints me is the...
0
1184
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? function date_selection($default_date="", $field_names=array("user_birthday_month", "user_birthday_day", "user_birthday_year"), $labels=1) // Returns date selection as a drop-down menu, if field names are omitted birthday fields are used { //...
0
8808
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8712
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9316
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9021
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7954
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6637
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4465
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4727
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2113
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.