how to hide an if statment? or whatever technique can be done?
I have an external javascript file, and it has multiple if statements, the problem is, one of the if statements is still being called even if the form is hidden. my application goes like this, - when a user is logged-in, hide this particular input form - if not logged-in, show the input form
so that's the problem, the if statement for that input form using jav开发者_Python百科ascript, is still being called even if the input form is hidden, so what should I do to solve this?
here is the if statement for the input form
if(cvusername == "" || cvusername.length < 5 || cvusername.length > 30){
alert("-username is required\n-should not be less than 5 characters\n and not greater than 30 characters");
return false;
}
Suppose that your input form's id is input_form, do this:
if(document.getElementById("input_form").style.display !== "none"
&& (
cvusername == ""
|| cvusername.length < 5
|| cvusername.length > 30)
){
alert("-username is required\n-should not be less than 5 characters\n and not greater than 30 characters");
return false;
}
Either remove that script from your pages or set cvusername to any string between 5 and 30 characters, in every page.
cvusername = "loggedin";
精彩评论