My JavaScript functions are undefined (to FireFox's opinion)

JavaScript and client side scripting.

Moderator: General Moderators

User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

Try without the . between the elements and [NAME].

Code: Select all

if (document.elements[NAME][i].checked==true)
pilau
Forum Regular
Posts: 594
Joined: Sat Jul 09, 2005 10:22 am
Location: Israel

Post by pilau »

CoderGoblin wrote:Try without the . between the elements and [NAME].

Code: Select all

if (document.elements[NAME][i].checked==true)
It then says:

Error: document.elements has no properties
Source File: http://www.wormiverse.com/rewclan/calendar.php
Line: 21
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

may be this does wot you are looking for.

Code: Select all

<script>
	function getStatus(name){
		var inps = document.getElementsByName(name); 
		//alert(inps);
		//alert(inps.length);
		var i = 0;
		var checked;
		for(i = 0; i < inps.length; i++){
			//alert(inps[i].value);
			//alert(inps[i].name);
			if(inps[i].value == "main"){
				var checked = inps[i].checked;
				alert("got the value main");
			}
			//alert(inps[i].checked);
			//alert(inps[i].type);
		}

		for(i = 0; i < inps.length; i++){
			inps[i].checked = checked;
		}
		
		
	}
</script>
january <input type='checkbox' value = 'main' name = 'January' onblur='getStatus("January")' />
january item 1<input type='checkbox' value = '23' name = 'January' onblur='getStatus("January")' />
january item 2<input type='checkbox' value = '2' name = 'January' onblur='getStatus("January")' />
january item 3<input type='checkbox' value = '30' name = 'January' onblur='getStatus("January")' />
january item 4<input type='checkbox' value = '14' name = 'January' onblur='getStatus("January")' /><br /><br />

February <input type='checkbox' value = 'main' name = 'February' onblur='getStatus("February")' />
February item 1<input type='checkbox' value = '25' name = 'February' onblur='getStatus("February")' />
February item 2<input type='checkbox' value = '14' name = 'February' onblur='getStatus("February")' />
February item 3<input type='checkbox' value = '6' name = 'February' onblur='getStatus("February")' />
February item 4<input type='checkbox' value = '27' name = 'February' onblur='getStatus("February")' />
pilau
Forum Regular
Posts: 594
Joined: Sat Jul 09, 2005 10:22 am
Location: Israel

Post by pilau »

Rag, I get no errors but it's just not working. :P
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

the event is actually onblur so you have to click on any of the first check boxes (january or february) and click anywhere on the body so trigger the onblur event.

actually you have to change that event later on...but that works... :)
pilau
Forum Regular
Posts: 594
Joined: Sat Jul 09, 2005 10:22 am
Location: Israel

Post by pilau »

Nope, it's only half-working.

See, your function can DISABLE the checkboxes, but not ENABLE them back after they've been disable.
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

pilau, it works well in my system. try it again mate.

refresh the page; check any of the first boxes and click anywhere in the body. that should check all other boxes of the group.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

You may want to shift click on Reload or clear your cache. (Javascript is often cached rather than reloaded in Firefox).
pilau
Forum Regular
Posts: 594
Joined: Sat Jul 09, 2005 10:22 am
Location: Israel

Post by pilau »

Good idea.
Well, I fixed and changed some of the things, added some of my own code, and it's just perfect. Thanks a lot for all who helped me!
Post Reply