HTML, JavaScript And CSS Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingHTML, JavaScript And CSS Help

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 ASP Free Forums Sponsor:
  #1  
Old December 2nd, 2003, 07:44 PM
shamrog12's Avatar
shamrog12 shamrog12 is offline
Newton's Apple Wizard
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Nov 2003
Location: Los Angeles
Posts: 1,661 shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Weeks 2 Days 2 h 39 m 22 sec
Reputation Power: 34
Send a message via AIM to shamrog12
Loop through form fields

I gave up on Javascript a while ago and now it's haunting me again. I have a form... a huge form. I want to be able to cycle through the form fields to see if they're all blank or not. I don't know if there is a way to reference form elements by index number and do something magical such as a For loop where I can say formname.getElement[i] and just go through them all.

Anyone able to decipher what I want and tell me what I have to do to do this?

Reply With Quote
  #2  
Old December 3rd, 2003, 02:48 AM
dev257 dev257 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Chandigarh
Posts: 55 dev257 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 40 m 48 sec
Reputation Power: 5
try


formname.item(index).value

Reply With Quote
  #3  
Old December 3rd, 2003, 02:53 AM
dev257 dev257 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Chandigarh
Posts: 55 dev257 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 40 m 48 sec
Reputation Power: 5
try


formname.item(index).value

Reply With Quote
  #4  
Old December 4th, 2003, 08:23 PM
vaza vaza is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 11 vaza User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I have used the if statement:

if (formname.elements[i].value=="")
{
alert("your message")
}

I hope this helps.

Reply With Quote
  #5  
Old December 4th, 2003, 11:00 PM
shamrog12's Avatar
shamrog12 shamrog12 is offline
Newton's Apple Wizard
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Nov 2003
Location: Los Angeles
Posts: 1,661 shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Weeks 2 Days 2 h 39 m 22 sec
Reputation Power: 34
Send a message via AIM to shamrog12
Thanks!

What I ended up was using a combination of this script and this submit button at the bottom of the form. Worked great!

Code:
<script language="JavaScript" type="text/javascript">
function checkForEmpties(form) {
	var counter;
	var formElements = form.elements;
	var proceed;

	for (i=0; i<formElements.length; i++) {
		return(formElements[i].value!="");
	}
}
</script>

.
.
.
.
.
<input name="Submit" type="submit" value="Search for Matching Records" onClick="if (!checkForEmpties(this.form)){alert('Please provide search criteria.'); return false;}">

Reply With Quote
  #6  
Old December 4th, 2003, 11:23 PM
shamrog12's Avatar
shamrog12 shamrog12 is offline
Newton's Apple Wizard
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Nov 2003
Location: Los Angeles
Posts: 1,661 shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Weeks 2 Days 2 h 39 m 22 sec
Reputation Power: 34
Send a message via AIM to shamrog12
ok, scratch that. it doens't work afterall. I need help now :-/

This returns the FIRST element. I need it to check to see if all are false etc.

Help please?

Reply With Quote
  #7  
Old December 4th, 2003, 11:44 PM
shamrog12's Avatar
shamrog12 shamrog12 is offline
Newton's Apple Wizard
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Nov 2003
Location: Los Angeles
Posts: 1,661 shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Weeks 2 Days 2 h 39 m 22 sec
Reputation Power: 34
Send a message via AIM to shamrog12
Maybe this one works. It SEEMS to work for me. Take the code if you want it. I promise nothing.

Code:
<script language="JavaScript" type="text/javascript">
function checkForEmpties(form) {
	var i;
	var formElements = form.elements;
	var proceed;

	for (i=0; i<formElements.length; i++) {
		if (formElements[i].type == "text") {
			if (formElements[i].value != "") {
				return true;
				break;
			}
		}
		else if (formElements[i].type == "checkbox") {
			if (formElements[i].checked) {
				return true;
				break;
			}
		} 
		
	}
	return false;
}
</script>

Reply With Quote
  #8  
Old December 5th, 2003, 08:18 PM
vaza vaza is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 11 vaza User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Your code looks very promising, think i'll use it sometime, seems to make validation a whole lot easier...Thanks for the offer . One thing though is that if i use this script how do i call up an alert box if any one of the fields are empty or unchecked.....also how do i trap values in the fields that have already been filled instead of having the user fill out the whole form again instead of just the empty fields

Reply With Quote
  #9  
Old December 5th, 2003, 09:06 PM
shamrog12's Avatar
shamrog12 shamrog12 is offline
Newton's Apple Wizard
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Nov 2003
Location: Los Angeles
Posts: 1,661 shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Weeks 2 Days 2 h 39 m 22 sec
Reputation Power: 34
Send a message via AIM to shamrog12
what you need for some real validation

If you're interested in straight form validation I would use the attached files. Together they're GREAT.

The code that I posted will search through a form and if any of hte boxes are empty it will simply not submit the form. It worked for what I had to do but what I'm posting might be better. What it does is go through a form and if a form is blank but you require it to be filled, the form will alert the user that the form is empty and then give focus to the part of the form that is not correct. It's a little difficult to learn at first but you should get it. I'm an absolute pro at it after using it about 100 times literally. Took about 10 to know what I was doing. I broke it so many times. Use mozilla's built in javascript debugging for help on this one. Your form will be GREAT.
Attached Files
File Type: zip javascriptchek.zip (15.1 KB, 601 views)

Reply With Quote
  #10  
Old December 6th, 2003, 09:04 AM
vaza vaza is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 11 vaza User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks for the script I will use it and get back to u. Its a script that I have been looking for it for a long time now....

Reply With Quote
  #11  
Old December 6th, 2003, 12:30 PM
shamrog12's Avatar
shamrog12 shamrog12 is offline
Newton's Apple Wizard
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Nov 2003
Location: Los Angeles
Posts: 1,661 shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Weeks 2 Days 2 h 39 m 22 sec
Reputation Power: 34
Send a message via AIM to shamrog12
well it's the best one I've found and those folks at Netscape know their stuff. It's VERY cross-browser friendly. I have not found a browser that does not work with it yet. For cross-browser compatibility stay away from Microsoft's scripts.

Reply With Quote
  #12  
Old June 30th, 2004, 10:17 AM
gn0mad gn0mad is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 4 gn0mad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m
Reputation Power: 0
Hey, which mozilla build has debugging for javascript?

Reply With Quote
  #13  
Old June 30th, 2004, 10:21 AM
shamrog12's Avatar
shamrog12 shamrog12 is offline
Newton's Apple Wizard
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Nov 2003
Location: Los Angeles
Posts: 1,661 shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Weeks 2 Days 2 h 39 m 22 sec
Reputation Power: 34
Send a message via AIM to shamrog12
all. all you have to do on a page is type "javascript:" (without the quotes) into the address bar and the javascript debugger comes up. Same goes for Netscape and Mozilla Firefox.
__________________
If you found a post of mine helpful, please click on the on my post to add to my reputation.


Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingHTML, JavaScript And CSS Help > Loop through form fields


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 | 
  
 
<