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

adding validation to existing code

Status
Not open for further replies.

cat5ive

MIS
Dec 3, 2004
184
US
Hi,

My asp is currently do validate on client side only. When user click save it call function to validate and pop up alert box if there is an error. Now I need to add server side validation, to validate if product exist. If it doesn't then pop up the alert box. I don't know where to insert the change since it's server side validation. Can someone please help?
Thanks in advance

function to validate
Code:
<script type="text/javascript" defer>
	 <!--
 function check_input()
	    {    
 if (lTrim(product.value)=="")
		   {
		     alert ("Product# is Required");
			 product.focus();
			 return false; 
		   }	
 // some more validate for other fields	

   document.f1.flag.value = "1"				   
		   return true;		  
		}		
	 
	  -->
	</script>
my form
Code:
<form action="mypage.asp" method="post" name="f1"> 
/// some data input fields
<td><input type="image" name="save" value="f1" src="images/btn_save_cream.gif" border="0"  onclick="return check_input();"></td>
 
There's no one to alert on the server. The process isn't even running on the console in a way that even if you were sitting at the web server, there would be any way to pop up a message for the webmaster to click "OK" on.

In your mypage.asp which receives the form, you have to check your function (without the alert and focus statements) and if it returns false, redisplay the same page as the user was on before, with the fields still filled in with his chosen values. You could do this with a redirect, or Server.Transfer.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top