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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

validate textfield

Status
Not open for further replies.

carranz

Technical User
Nov 17, 2006
40
US
I have this validatation code. It works but for some reason after the alert box comes up saying a field needs to be input I hit ok then the form goes through its process I want to process to stop so I can go back and input into the field
any help would be appreciated


<script Language="JavaScript">
<!--
function Blank_TextField_Validator()
{
// from the form named form
if (form2.first.value == "")
{
alert("Please fill in the First Name.");
first.focus();
// return false to stop further processing
return (false);
}
// If text_name is not null continue processing
return (true);
}
-->
</script>
 
You need to make sure you return the result from the function in your onsubmit event on the form:
Code:
<form id="whatever" method="post" action="somepage.asp" onsubmit="[!]return [/!]Blank_TextField_Validator()">

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
Ok that worked
Problem now is I have three texboxes that need to validated if they are empty. for some reason it will pick up the first textfield but not the other so I testing it

I input something in the first textfield and hit submit and it goes through without validating the other empty textfields

here is my code

<script Language="JavaScript">
<!--
function Blank_TextField_Validator()
{
// from the form named form
if (form2.first.value == "")
{
alert("Please fill in the First Name.");
first.focus();
// return false
return (false);
}
// If text_name is not null continue processing
return (true);

// return false to stop further processing
if (form2.last.value == "")
{
alert("Please fill in the Last Name.");
last.focus();
// return false
return (false);
}
// If text_name is not null continue processing
return (true);

// return false to stop further processing
if (form2.dept.value == "")
{
alert("Please fill in the Directory.");
dept.focus();

// return false
return (false);
}
// If text_name is not null continue processing
return (true);
}
}
}
-->
</script>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top