how do i code it as javascript when user leave the field empty, they will direct the user to another page?
i'm using asp.net..
how do i code it as javascript when user leave the field empty, they will direct the user to another page?
i'm using asp.net..
if (form.field.value == "") window.location="otherpage.html";
This little line should be in a function called from your <form>'s onSubmit() event. If you mean anything else you're going to need to be more specific.
You first have to decide whether you want to validate your fields on server side or on client side. Client side validation is performed before the form is submitted to the server. Server side validation is performed after the form submission.
For client side validation, you need nothing else but javascript. For this purpose you can write a method:
function validate(){
if(document.myForm.myField.value=="")
window.location="mypage.aspx";
}
Then put this method in onSubmit attribute:
<form name="myForm" onsubmit="validate()"></form>
If you are using an iframe then you will replace window.location with <<iframeName>>.src
For server side validation, I don't know how to do it in ASP but we usually do it in JSP like this:
String myField = request.getParameter("myField");
if(myField==null || "".equals(myField))
response.sendRedirect("myPage.jsp");
The above code is written in a scriplet in the JSP whom the form is targetting on submission.