Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 4th, 2005, 11:45 AM   #1
fmontoya
Newbie
 
Join Date: Apr 2005
Posts: 2
Rep Power: 0 fmontoya is on a distinguished road
Need help with required form script

I am trying to use a required form script for this web page:
http://www.lansce.lanl.gov/reg_form.html

I cant seem to get it to work. I'm not sure if I need to put it somewhere different in my source code. It is located at the bottom prior to the end of the body. Can someone please look at source and give advice. Thanks.
fmontoya is offline   Reply With Quote
Old Apr 4th, 2005, 11:56 AM   #2
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
this is what i use:

 function checkrequired(which) 
 {
 	var pass=true;
 	if (document.images) 
 	{
 		for (i=0;i<which.length;i++) 
 		{
 			var tempobj=which.elements[i];
 			if (tempobj.name.substring(0,8)=="required") 
 			{
 				if (((tempobj.type=="text"||tempobj.type=="textarea")&&tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&tempobj.selectedIndex==0)) 
 				{
					pass=false;
 					break;
 			         }
       			}
 		}
 	}
 	if (!pass) 
 	{
 		shortFieldName=tempobj.name.substring(8,30).toUpperCase();
 		alert("Please make sure the "+shortFieldName+" field was properly completed.");
 		return false;
 	}
 	else
 	{
 		return true;
 	}
 }

then in the form tag put:

 <form method="blahblah" action="blahblah" name="myform" onsubmit="return checkrequired(this);">
The key is the onsubmit part....

then when your coding the form element that you want to be required do this:

 <input type="text" name="requiredMyTextElement">

what that does is any form element that has the word required in the name it will check to see if there is a value inserted in the element. I found this script on some site a while back.
__________________
Profanity is the one language that all programmers understand.

Check out my Blog <---updated Nov 30 2007!
Pizentios is offline   Reply With Quote
Old Apr 4th, 2005, 12:11 PM   #3
fmontoya
Newbie
 
Join Date: Apr 2005
Posts: 2
Rep Power: 0 fmontoya is on a distinguished road
Thank you for your help. I'm going to attempt to get it to work.
fmontoya is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:52 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC