AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.



jsp-javascript: How to do validation before submitting data using jsp?

I have the student registration form with fields like Sid, SName, Address. When I click submit button these data should store in oracle db. Before storing of data perform the validations. If user forgot to enter his data in fields and hit the submit button then data should not store in database.After entering all details the data should store in database.

Ecplain the concept with example code.


jsp x 32
javascript x 28
Posted On : 2016-09-06 22:00:02.0
profile MOHAMMAD SALEEM BASHA - anyforum.in MOHAMMAD SALEEM BASHA
266150
up-rate
2
down-rate

Answers


to validate form data before submitting it, we have to use javascript form validation or jquery.

<script>
function validate(){
var name=document.f1.name.value;
var password=document.f1.password.value;
var status=false;

if(name.length<1){
document.getElementById("nameloc").innerHTML=
"Please enter your name";
status=false;
}else{
document.getElementById("nameloc").innerHTML="";
status=true;
}
if(password.length<6){
document.getElementById("passwordloc").innerHTML=
"Password must be at least 6 char long";
status=false;
}else{
document.getElementById("passwordloc").innerHTML="";
}
return status;
}
</script>

<form name="f1" action="#" onsubmit="return validate()">
<table>
<tr><td>Enter Name:</td><td><input type="text" name="name"/>
<span id="nameloc"></span></td></tr>
<tr><td>Enter Password:</td><td><input type="password" name="password"/>
<span id="passwordloc"></span></td></tr>
<tr><td colspan="2"><input type="submit" value="register"/></td></tr>
</table>
</form>

Output:
-------------------------
Enter Name:
Enter Password:

Posted On : 2016-09-06 23:10:39
Satisfied : 2 Yes  0 No
profile Rishi Kumar - anyforum.in Rishi Kumar
523185319357
Reply This Thread
up-rate
5
down-rate



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in