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

"Clear All" items in a SELECT MULTIPLE box via JavaScript

Greetings,

I've been working on this for a few hours now. It seems to be a pretty
simple task but I keep running into "[element] has no properties".

I have a select box defined as follows:

<SELECT MULTIPLE NAME="myOptions[]" SIZE=5>
<OPTION VALUE="Blue">Blue</OPTION>
<OPTION VALUE="Red">Red</OPTION>
<OPTION VALUE="Green">Green</OPTION>
</SELECT>

The options are submitted to a PHP script which takes $myOptions as an
array for parsing.

All I want to do is give the user the ability to clear all of their
selected options. I don't want to actually remove the item from the
list, just de-select it. You get the idea... I've tried every
variation I can think of and I've been searching the web and usenet
for quite some time.

A function like this SHOULD do the job:

function uncheckAll() {
var obj = document.getElementById('myOptions');
for (var i=0; i < obj.options.length; i++) {
obj.options[i] = null;
}
}

But I keep getting told that "obj has no properties" on the "for"
line. I could use checkboxes and there wouldn't be any problems, but
eventually there will be 3 or 4 of these SELECT boxes on the page. I'd
like to keep the layout clean by using them instead of making big
lists of checkboxes.

This seems like a simple thing to do... but after 3+ hours of
searching, and trying many different methods, I'm still hitting a
brick wall. Granted I don't do much JavaScript these days, but I'd
sure like some help. If someone could give me a shove in the right
direction, it'd be appreciated.

- RK -

Jun 1 '07 #1
3 16365
Lee
Robert Kilroy said:
>
Greetings,

I've been working on this for a few hours now. It seems to be a pretty
simple task but I keep running into "[element] has no properties".

I have a select box defined as follows:

<SELECT MULTIPLE NAME="myOptions[]" SIZE=5>
<OPTION VALUE="Blue">Blue</OPTION>
<OPTION VALUE="Red">Red</OPTION>
<OPTION VALUE="Green">Green</OPTION>
</SELECT>

The options are submitted to a PHP script which takes $myOptions as an
array for parsing.

All I want to do is give the user the ability to clear all of their
selected options. I don't want to actually remove the item from the
list, just de-select it. You get the idea... I've tried every
variation I can think of and I've been searching the web and usenet
for quite some time.

A function like this SHOULD do the job:

function uncheckAll() {
var obj = document.getElementById('myOptions');
for (var i=0; i < obj.options.length; i++) {
obj.options[i] = null;
}
}

But I keep getting told that "obj has no properties"
You gave it the name "myOptions[]".
You didn't give it any id at all.
Why are you expecting document.getElementById('myOptions') to find it?
Give it an id, if you want to use getElementById().

See also:
http://www.jibbering.com/faq/#FAQ4_25
--

Jun 1 '07 #2
Ahhh! The one thing I didn't try... putting the brackets in as part of
the variable. I guess I assumed that MULTPLIE SELECTs were arrays by
default.

This function works in Firefox and IE6:

function uncheckAll() {
var obj = document.frmlisting.elements["myOptions[]"];
for (var loop=0; loop < obj.options.length; loop++) {
obj.options[loop].selected = false;
}
}

That's what I get for not keeping up with my JavaScript I guess...
Thanks!

(And yes, the Javascript FAQ is bookmarked) :)

On Jun 1, 5:05 pm, Lee <REM0VElbspamt...@cox.netwrote:
You gave it the name "myOptions[]".
You didn't give it any id at all.
Why are you expecting document.getElementById('myOptions') to find it?
Give it an id, if you want to use getElementById().

See also:http://www.jibbering.com/faq/#FAQ4_25

--

Jun 1 '07 #3
ASM
Robert Kilroy a écrit :
function uncheckAll() {
var obj = document.getElementById('myOptions');
for (var i=0; i < obj.options.length; i++) {
obj.options[i] = null;
obj.options[i].selected = false;
}
}

But I keep getting told that "obj has no properties"
yes that right ...
which property do you see in obj.options[i] ?
or : could options[i] be a property of obj ?

obj.options[i].text
obj.options[i].value
obj.options[i].selected
obj.options[i].id
obj.options[i].style
...
--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Jun 2 '07 #4

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

Similar topics

10
by: KENNY L. CHEN | last post by:
Dear experts, I have two tables in my Oracle 8i database: TEST (COL1,COl2,REC_NO) and TEST1 (COL1,COL2,REC_NO). Both tables are unique-indexed on (COL1,COL2,REC_NO). I think the following...
4
by: Jack | last post by:
I finally discovered where all of the blue boxes in my IDE are coming from after, once again, accidently hitting "Mark All" in a Find in the Visual Studio.NET IDE. However, there is no "Unmark...
3
by: Not Me | last post by:
Hi, Is there any criteria I can use in my where clause to say 'anything'? Maybe like the _ used in some languages? For my example, I want to use an inline-if, so if a checkbox is ticked I say...
7
by: Jaime Stuardo | last post by:
Hi all.. I have a DataGrid with checkboxes. In the header I have a "check all" checkbox. I'm wondering if there is an easy way to check all checkboxes using that checkbox. I could do it using...
3
by: Jimmy | last post by:
I use a combo box to filter the results of a form. Sql for combo box is... SELECT StatusPriority, Status FROM tblStatus UNION Select = 0 as AllChoice, "Show All" as Bogus From tblStatus ORDER...
1
by: sherifffruitfly | last post by:
Hi, I've got a checked list box, and a "go' button on the form. Each item in the checked list box is associated with a program (say notepad, calc, etc.). When the user clicks "go", every item...
6
jlandbw04
by: jlandbw04 | last post by:
Okay. Here's the deal. I have this assignment for college that has me completely puzzled. I need this assignment to do the following: 1. input 12 integers into an array from the user. 2. output...
4
by: Pandu | last post by:
Hello: Our HR dept wants to allow users to download various HR forms from our comp intranet. But since there are over 20 forms, I need to allow users to select the files they want and then...
1
by: Jenniferdb2 | last post by:
Hello All, create table a (i int); create table b(i int); insert into a values(1); ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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: 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...
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.