JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 17th, 2006, 05:04 PM
Xaphan's Avatar
Xaphan Xaphan is offline
O_o wats this button do???
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: Kent, England
Posts: 488 Xaphan User rank is Sergeant (500 - 2000 Reputation Level)Xaphan User rank is Sergeant (500 - 2000 Reputation Level)Xaphan User rank is Sergeant (500 - 2000 Reputation Level)Xaphan User rank is Sergeant (500 - 2000 Reputation Level)Xaphan User rank is Sergeant (500 - 2000 Reputation Level)  Folding Points: 2427 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 42 m 16 sec
Reputation Power: 29
Number of forms on a page

is there an easy way to find out how many forms there are on a page?

what i want to do is change the onsubmit attribute of ALL my forms, but in such a way that i can easily change it again, so i was thinking along the lines of:

Code:
for(var a = 0; a < document.forms.length; a++) {
document.forms[a].onsubmit = 'return false;';
}


this is probably way off the mark, but i cant think of another way of doing it.
__________________
Xaphan

Have I helped you? Then help me, and click the rep. button, top right ()

Reply With Quote
  #2  
Old June 17th, 2006, 05:40 PM
Xaphan's Avatar
Xaphan Xaphan is offline
O_o wats this button do???
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: Kent, England
Posts: 488 Xaphan User rank is Sergeant (500 - 2000 Reputation Level)Xaphan User rank is Sergeant (500 - 2000 Reputation Level)Xaphan User rank is Sergeant (500 - 2000 Reputation Level)Xaphan User rank is Sergeant (500 - 2000 Reputation Level)Xaphan User rank is Sergeant (500 - 2000 Reputation Level)  Folding Points: 2427 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 42 m 16 sec
Reputation Power: 29
ok, i have this now:

Code:
document.onload="load_funct;";

function load_funct() {
for(var a = 1; a <= document.forms.length; a++) {
document.forms[a].onsubmit = 'return false;';
}
}
and nothing happens, am i missing something?

Reply With Quote
  #3  
Old June 17th, 2006, 05:50 PM
Xaphan's Avatar
Xaphan Xaphan is offline
O_o wats this button do???
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: Kent, England
Posts: 488 Xaphan User rank is Sergeant (500 - 2000 Reputation Level)Xaphan User rank is Sergeant (500 - 2000 Reputation Level)Xaphan User rank is Sergeant (500 - 2000 Reputation Level)Xaphan User rank is Sergeant (500 - 2000 Reputation Level)Xaphan User rank is Sergeant (500 - 2000 Reputation Level)  Folding Points: 2427 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 42 m 16 sec
Reputation Power: 29
Talking

ok, now i have this, its almost working... BUT.

Code:
function page_load()
{
	for(var a = 0; a < document.forms.length; a++)
	{
		document.forms[a].onSubmit = "alert('Please submit the form correctly by clicking the appropriate button.');return false;";
	}
}


i put the onload directly into the HTML body tag.

this is not actually setting the onsubmit attribute for the forms, as the alert is not appearing, and the form is submitting.

this works if i hard-code it into the <form> tag, but not by this javascript.

am i missing something quite simple? i've been at this for the best part of 90 mins now... lol.

thanks

Reply With Quote
  #4  
Old June 17th, 2006, 06:22 PM
ChiefWigs1982's Avatar
ChiefWigs1982 ChiefWigs1982 is offline
Cunning Linguist
Dev Shed God 11th Plane (10000 - 10499 posts)
 
Join Date: Jul 2003
Location: I used to live at home, now I stay at the house
Posts: 10,180 ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)ChiefWigs1982 User rank is General 16th Grade (Above 100000 Reputation Level)  Folding Points: 50746 Folding Title: Beginner FolderFolding Points: 50746 Folding Title: Beginner FolderFolding Points: 50746 Folding Title: Beginner Folder
Time spent in forums: 3 Months 3 Weeks 5 Days 19 h 54 m 23 sec
Reputation Power: 2037
Try:
Code:
document.forms[a].onsubmit=function() {
   alert('Please submit the form correctly by clicking the appropriate button.');
   return false;
}

Also, notice that 'onsubmit' is all lowercase.
__________________
Support requests via PM will be ignored!
Sites: WordPress Metro Theme | Route of Queue
Read These: The General Rules Thread | The General FAQ Thread | NEW USERS - How to post a question


Reply With Quote
  #5  
Old June 18th, 2006, 04:58 AM
Xaphan's Avatar
Xaphan Xaphan is offline
O_o wats this button do???
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: Kent, England
Posts: 488 Xaphan User rank is Sergeant (500 - 2000 Reputation Level)Xaphan User rank is Sergeant (500 - 2000 Reputation Level)Xaphan User rank is Sergeant (500 - 2000 Reputation Level)Xaphan User rank is Sergeant (500 - 2000 Reputation Level)Xaphan User rank is Sergeant (500 - 2000 Reputation Level)  Folding Points: 2427 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 42 m 16 sec
Reputation Power: 29
like this?
Code:
function page_load()
{
	for(var a = 0; a < document.forms.length; a++)
	{
		document.forms[a].onsubmit=function()
		{
			alert('Please submit the form correctly by clicking the appropriate button.');
			return false;
		}
	}
}


i was trying different ways of writing onsubmit to see if it made a difference.

Reply With Quote
  #6  
Old June 18th, 2006, 05:06 AM
Xaphan's Avatar
Xaphan Xaphan is offline
O_o wats this button do???
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: Kent, England
Posts: 488 Xaphan User rank is Sergeant (500 - 2000 Reputation Level)Xaphan User rank is Sergeant (500 - 2000 Reputation Level)Xaphan User rank is Sergeant (500 - 2000 Reputation Level)Xaphan User rank is Sergeant (500 - 2000 Reputation Level)Xaphan User rank is Sergeant (500 - 2000 Reputation Level)  Folding Points: 2427 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 42 m 16 sec
Reputation Power: 29
hey, it WORKS!

thankyou very very much!

thats made a good start to my day...
Comments on this post
ChiefWigs1982 agrees: Glad you got it working.

Reply With Quote
  #7  
Old June 19th, 2006, 04:45 AM
Xaphan's Avatar
Xaphan Xaphan is offline
O_o wats this button do???
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: Kent, England
Posts: 488 Xaphan User rank is Sergeant (500 - 2000 Reputation Level)Xaphan User rank is Sergeant (500 - 2000 Reputation Level)Xaphan User rank is Sergeant (500 - 2000 Reputation Level)Xaphan User rank is Sergeant (500 - 2000 Reputation Level)Xaphan User rank is Sergeant (500 - 2000 Reputation Level)  Folding Points: 2427 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 42 m 16 sec
Reputation Power: 29
is there any way to retreive the form name from this?

meybe
Code:
document.forms[a].name
or will that try to look for an element called name in the form?

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Number of forms on a page

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap