Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

a standard validate form function

Status
Not open for further replies.

tonyx666

MIS
Joined
Apr 13, 2006
Messages
214
Location
GB
hi.. someone kindly gave me the below script that makes sure one of my radio buttons is checked before the user can press submit.. my question is this..
is there a basic procedure that i can use that will place rules on the other form inputs..

so if they do not choose an item from a drop down.. or do not write text in a textbox.. and so on.. also can all of these commands be placed in one function.. as opposed to wrting a separate function for each part of the form validation..

if someone could show me a general snippet that is not to hard to manipulate i would be very grateful.. thanks..

Code:
<script type="text/javascript">
			<!--
			function doRedirect()
			{
			var groupValue;
			var myOption = -1;
			for (i=document.form.r1.length-1; i > -1; i--) {
			if (document.form.r1[i].checked) {
			groupValue = document.form.r1[i].value;
			myOption = i;
			}
			}
			if (myOption == -1) {
			alert("You must select an option. \n e.g: Take me to Heathrow");
			return false;
			}
			else {return true;}
			}
			-->
		</script>
 
Make sure this:
[tt] onsubmit="[blue]return[/blue] IsFormComplete()"[/tt]

Also take out the semo-colon after the closing curly bracket of the function. It is a left-over of my previous incomplete editing. ([tt]}[highlight];[/highlight][/tt])
 
ok with this
Code:
function IsFormComplete()
{
    var FormOk  = true;

    if (document.EnquiryForm.ContactName.value == '')
    {
        alert('Please enter a '+document.EnquiryForm.ContactName.name +'.');
        document.EnquiryForm.ContactName.focus();
        FormOk = false;
        return FormOK;
    };
    
    if (document.EnquiryForm.EmailAdd.value == '')
    {
        alert('Please enter a '+document.EnquiryForm.EmailAdd.name +'.');
        document.EnquiryForm.EmailAdd.focus();
        FormOk = false;
        return FormOK;
    };


    return FormOk;
}
and this form call im still gettin that same prob..

Code:
				<form name="EnquiryForm" method="post" action="sendenquiry.asp" onSubmit="return IsFormComplete()">
 
>[tt]return FormOK;[/tt]
[tt]return FormO[COLOR=red yellow]k[/color];[/tt]

 
I should add, sorry, my bad!
 
i seee. its case sensitive.. i didnt know that.. thank you tsuji.. it works
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top