473,396 Members | 1,814 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,396 software developers and data experts.

this.form.elements.length results in 0

dan
I am a bit of a java newbie so please forgive me.

I am trying to do a simple check-all / un-check-all checkbox system.
All of the solutions I have seen use "this.form.elements.length" or a
variant of this.

My scripts don't work because "this.form.elements.length" always
returns 0. Example:

document.write(this.FormName.elements.length);

displays "0"

Am I missing something obvious here?

Thanks,

Dan T

Apr 1 '06 #1
3 7233
wrote on 01 apr 2006 in comp.lang.javascript:
I am a bit of a java newbie so please forgive me.
You certainly are, Java being a language that is OT here.

Javascript is NOT a script version of Java, but quite another language.
I am trying to do a simple check-all / un-check-all checkbox system.
All of the solutions I have seen use "this.form.elements.length" or a
variant of this.

My scripts don't work because "this.form.elements.length" always
returns 0. Example:

document.write(this.FormName.elements.length);

displays "0"

Am I missing something obvious here?


Yes:

Firstly, "this" only can be used AFTER the DOM has constructed the form,
so can only be called from an onclick or onmouseover etc.
document.write() then will destroy the whole page INCLUDING the script on
page.

Secondly, try:

<form name=f>
<input name=c type=checkbox>
<input name=c type=checkbox>
<input name=c type=checkbox>
<input name=c type=checkbox>
</form>

number of checkboxes:
<script type='text/javascript'>
document.write(document.forms['f'].elements['c'].length)
</script>


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Apr 1 '06 #2
Evertjan. wrote on 01 apr 2006 in comp.lang.javascript:
wrote on 01 apr 2006 in comp.lang.javascript:
I am a bit of a java newbie so please forgive me.


You certainly are, Java being a language that is OT here.

Javascript is NOT a script version of Java, but quite another language.


And you are forgiven....

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Apr 1 '06 #3
JRS: In article <11**********************@e56g2000cwe.googlegroups .com>
, dated Fri, 31 Mar 2006 23:37:25 remote, seen in
news:comp.lang.javascript, da*@tappin.ca posted :
I am a bit of a java newbie so please forgive me.

^^^^

To avoid making foolish mistakes like that again, you should seek and
read the newsgroup FAQ before posting.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Apr 2 '06 #4

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

Similar topics

2
by: Jan Roland Eriksson | last post by:
Archive-name: www/stylesheets/authoring-faq Posting-Frequency: twice a week (Mondays and Thursdays) Last-modified: August 28, 2002 Version: 1.15 URL: http://css.nu/faq/ciwas-aFAQ.html...
2
by: Laurent Bertin | last post by:
Hi i got a strange problem but it's true i don't make thing like anyone... First Config: + IIS5.0 SP2 (yes i know...) WebSite Security Root : Digest Authentication, NT Authenticated SubFolders...
10
by: Steve Benson | last post by:
Our regular programmer moved on. I'm almost clueless in Javascript/ASP and got the job of adapting existing code. In the page below, everything works until I added the function checkIt() to...
6
by: WindAndWaves | last post by:
Hi Folks I have inhereted a script that I understand reasonably well, I just do not understand !/^\d+$/.test(el.value) what the hell does that mean? Below is the script (there are really...
5
by: Nick Calladine | last post by:
Learning : Loop to list all dropdown box values on a form Can some one point me in the right direction : I have a form which I want to loop through I basically want to get all the selected...
12
by: Pudlik, Szymon | last post by:
Hi, I've written some code: function onSubmit(form){ for (var i = 0; i < form.elements.lenght; i++){ if (form.elements.disabled == 1) form.elements.disabled = 0; }
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
1
by: kamleshsharmadts | last post by:
I am using Ajax with struts in web application. from jsp i am calling a function of ajax.js onclick of a button. code of that call function which calling from jsp given as below:- ...
4
by: SteveKlett | last post by:
I have a subset of form items that I need to perform different operations on (enable/disable, clear values, change style, etc) rather than hard code the IDs or names I would like to recursively...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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,...

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.