Hi all I have this script
<form id="logform">
<input class="login" name="login" type="text"><br />
<input class="password" name="password" type="password"><br />
<input class="submit" type="submit" value="login">
</form>
var username = $(".login").val();
var password = $(".password").val();
$(".submit").click(function() {
alert(username);
});
and when I type text in input and click submit alert is empty ?
Modify your code to assign value after submit:
$(".submit").click(function(){
var username = $(".login").val();
var password = $(".password").val();
alert(username);
});
Because, value are being assigned when page is called. That is why username is empty.
Use the below script with user name within click function
$(".submit").click(function(){
var username = $(".login").val();
alert(username);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With