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

validation fields

Status
Not open for further replies.

sirron

Programmer
Mar 11, 2004
139
US

I have this code, and I want to validate this textfield and make sure the textfield is not empty or null and if is pop up a menu or message

is there a way to do this?
any help would be appreciated


<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form name="form1" method="post" action="">

<input type="text" name="textfield">
<input type="submit" name="Submit" value="Submit">

</form>
</body>
</html>
 
This is something that would probably be best done using client-side script. You may need to tweak the syntax (javascript), but this should give you an idea of what you need:
Code:
function Validate()
{
 if form1.textfield is null || form1.textfield = ""
 {
  alert("You cannot leave this field blank");
  form1.textfield.focus();
  return false;
 }
 else
  return true;
}

...HTML section
<input type="text" name="textfield">
<input type="submit" name="Submit" value="Submit" onclick="return Validate();">

------------------------------------------------------------------------------------------------------------------------
If you don't have a sense of humor, you probably don't have any sense at all.
- Anonymous
 
I tried this but its not poping up an alert. Im using dreamweaver to develope the page. When I run this on client side its not doing anything?

Can someone help?

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
<!--
function validation() {
if document.form1.textfield.value == "" {
alert ('textfield is blank');
return false;
}
else
return true;
//-->
</script>
</head>

<body>

<form action="" method="post" name="form1">
<input name="textfield" type="text" value="">
<input type="submit" name="Submit" value="Submit">

</form>

</body>
</html>
 
<form action="" method="post" name="form1" [red]onSubmit="return validation();"[/red]>


Tony
________________________________________________________________________________
 
It's still not working. I think I'm getting an error on the page but I'm not sure where.

Do you see any problem in the code?


<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
<!--
function validation() {
if document.form1.textfield.value == "" {
alert ('textfield is blank');
return false;
}
else
return true;
//-->
</script>
</head>

<body>

<form action="" method="post" name="form1" onSubmit="return validation();">
<input name="textfield" type="text" value="">
<input type="submit" name="Submit" value="Submit">

</form>

</body>
</html>
 
Are you encountering a specific error message? That may help to troubleshoot the problem.

------------------------------------------------------------------------------------------------------------------------
If you don't have a sense of humor, you probably don't have any sense at all.
- Anonymous
 
Hello sirron,

Try change the name of the input type submit to be something else other than "submit"?

regards - tsuji
 
When you run the page...see at the left bottom of the page...you will see a message "Done" with yellow triangle ...double click on that to see the exact error message...

-L
 
Ok here is the code u want...

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<html>
<head>
</head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
<!--
function validation() {
if (document.form1.textfield.value == "")
{
alert ('textfield is blank');
return false;
}
else
return true;
}
//-->
</script>


<body>

<form action="" method="post" name="form1" onSubmit="return validation();">
<input name="textfield" type="text" value="">
<input type="submit" name="Submit" value="Submit">

</form>

</body>
</html>

Try that...

You had your code in the <Head> tags...

-L
 
The page comes up with an error on line 9

Error Expected '('
Code 0
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top