Well you cannot actually combine a javascript function with a php code. This is because PHP is server side, that is, the script is parsed and executed before the page loads, whereas javascript is client side, which works only after the page loads.
I suggest doing the entire login script in PHP using the 'post' method for submitting the form to a PHP script.
If you want to use Javascript, then use something like this:
Code: Select all
<script language="javascript" type="text/javascript">
function login()
{
var temp = document.form2.login.value ;
if(temp.length < 4)
{
alert('Login id should be atleast 4 characters long');
return false;
}
else if(temp.length > 20)
{
alert('Login id should not be more than 5 characters');
return false;
}
else
{
window.location = "?login="+temp
return true;
}
}
</script>
And then make use of the $_GET superglobal to query with the login details.
However, I strongly suggest using PHP to do the entire function of logging in as server side scripts are much more reliable in many ways.