473,574 Members | 2,474 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

this.form.eleme nts.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.elem ents.length" or a
variant of this.

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

document.write( this.FormName.e lements.length) ;

displays "0"

Am I missing something obvious here?

Thanks,

Dan T

Apr 1 '06 #1
3 7245
wrote on 01 apr 2006 in comp.lang.javas cript:
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.elem ents.length" or a
variant of this.

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

document.write( this.FormName.e lements.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.javas cript:
wrote on 01 apr 2006 in comp.lang.javas cript:
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************ **********@e56g 2000cwe.googleg roups.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.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.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
2812
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 Maintainer: Jan Roland Eriksson <rex@css.nu> ciwas stylesheet authoring FAQ v1.15 ______________________________________________________________________
2
2682
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 : Anonymous Login Anonymous login is set to use a domain user to enable a sql server authenticated connection. Permissions are based on...
10
3582
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 validate which radio button was clicked and what was in a textfield. The form is an attendance checking page for a cyber charter school. What I'm trying to...
6
23467
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 three and they validate a four items
5
3458
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 values of the option tag see example below
12
7296
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
4856
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 the html page controls the form fields that are required. It doesn't function like it's supposed to and I can leave all the fields blank and it still...
1
9474
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:- onclick="retrieveURL('/application/home_page.do?processAction=ItinerarySearch','AfoHomeForm')" after clicking on button i am getting following error:- object...
4
3193
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 search a parent element(in my case a <table>) and search for elements of a certain type (<input>, <textarea>, etc) and perform operations on them. ...
0
7794
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...
0
7710
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...
1
7800
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8092
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...
1
5610
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...
0
5296
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3738
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...
1
2230
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1051
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...

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.