I am calling a Javascript test()
function for validation purpose before it can be committed. This function has Java scriptlets where validation logic is return and it updated a boolean variable. Using this boolean variable, I am checking if this js function should return true or false. If false then it is negative case of validation and in true positive case of validation.
The general code is something like:
<% boolean check = false ; %>
<script>
function test(){
/*
* java code for updating test variable for validating values on the jsp page
*/
if(!check){
<% System.out.println("this runs ! "); %> // line 1
alert("validation fails"); // line 2
return false;
}
else return true;
}
</script>
..
..
<input type="submit".. onclick="return test()">
..
..
Is it going wrong somewhere? I have been trying a lot of things for line 1 to run, but it doesnt. My code execution reached inside the if check at line 1, but doesnt alert i.e line 2 and the validation thing also doesnt work.
Someone had similar issues? What is the resolution?