Reputation: 3903
I am new to stackoverflow i have doubt regarding calling jsp from javascript file. my file contain one html file with javascript(home.html) and one jsp file(login.jsp) In html(home.html) file i have 2 textbox and 2 buttons one for login and another for reset.when i click the login button i should call a js for textbox field validation (ie for if any one of the textbox is empty it shows "text fields should not be empty" alert msg to user)if both the textbox have value then it should call a jsp page(login.jsp).Thanks in advance
Upvotes: 2
Views: 43447
Reputation: 3903
<script language="JavaScript">
function val(){
var name=...
var pass=...
if(name==" "||pass==" ")
{
alert("fields should not be empty");
}
else{
var jspcall = "login.jsp?param1=value1¶m2=value2";
window.location.href = jspcall;
}
}
</script>
Upvotes: 2
Reputation: 14873
Try using jquery
$.post("login.jsp", { name: "John", time: "2pm" },
function(data){
alert("Data Loaded: " + data);
});
ref: http://api.jquery.com/jQuery.post/
Upvotes: 0
Reputation: 81384
<form id="myform" action="login.jsp" method="post">
<input name="u" id="u"> Username<br>
<input name="p" id="p" type="password"> Password
</form>
<script>
document.getElementById('myform').addEventListener('submit', function(e) {
if (!document.getElementById('u').value || !document.getElementById('p').value)
e.preventDefault();
}, false);
</script>
Upvotes: 1