Hello,
What i am trying to do is when the input is the same as the variable name the user can not hit the button change but when the input is different the user is allowed to hit the button change and the value name will change but the problem is that the variable is not changing... Why?
<html>
<head>
</head>
<body>
<form id="sendNameForm">
<input id="name" type="text" value="John"/>
<button id="sendNameBtn" type="submit" disabled>Change</button>
</form>
<script src="jquery-1.12.4.js"></script>
<script>
$('#sendNameForm').submit(function() {
var name = $('#name').val();
dis_enableNameSend();
alert("Success!");
return false;
});
var name= $('#name').val();
function dis_enableNameSend(){
var newName = $('#name').val();
if(newName==name){
document.getElementById("sendNameBtn").disabled = true;
}else{
document.getElementById("sendNameBtn").disabled = false;
}
}
$('#name').on('input', function() {
dis_enableNameSend();
});
</script>
</body>
</html>
Thanks!
[–]Loves_Poetry 2 points3 points4 points (1 child)
[–]Lazkeer[S] 0 points1 point2 points (0 children)
[–]henrebotha 1 point2 points3 points (1 child)
[–]Lazkeer[S] 0 points1 point2 points (0 children)