I’m trying to create fake login page with jQuery – purely for testing/template presentation purposes.
What form should do(see details in .js code):
Correct email: admin@admin.com / pass: admin
- check the values of the #username & #password against values in the .js
- if return true for both values alert ‘valid’ and go to home.html
- if not valid alert ‘not valid’ and display the error msg
Code at jsfiddle http://jsfiddle.net/MrTest/ZYZPY/
HTML
<form class="loginbox" autocomplete="off">
<fieldset>
<p style="display: none;" class="error">Error. Please enter correct email & password.</p>
<label for="username">E-mail</label>
<input type="text" id="username" />
<label for="username">Password</label>
<input type="password" id="password" />
<input type="submit" id="submit" value="LOG IN" />
</fieldset>
</form>
jQuery
$(document).ready(function() {
$('#username').focus();
$('#submit').click(function() {
event.preventDefault(); // prevent PageReLoad
$('.error').css('display', 'none'); // hide error msg
var ValEmail = $('#username').val('admin@admin.com'); // Email Value
var ValPassword = $('#password').val('admin'); // Password Value
if (ValEmail === true & ValPassword === true) { // if ValEmail & ValPass are as above
alert('valid!'); // alert valid!
window.location = "home.html"; // go to home.html
}
else {
alert('not valid!'); // alert not valid!
$('.error').css('display', 'block'); // show error msg
}
});
});
At the moment form always return else = false – why??
Any help much appreciated!
Pete
Working example: http://jsfiddle.net/MrTest/ZYZPY/12/
Should be
&&instead of&And
valis used to get the value of input, you should:A working fiddle: http://jsfiddle.net/DTGt9/