I am wondering if I can change the color of the button after everything in form is filled in. I think I have to do it with jQuery, but I'm not sure how to do it.
here is my code for the form:
<form action="">
<div>
<label for="name"></label>
<input type="text" id="name" name="user_name" placeholder=" Full Name">
</div>
<div>
<label for="mail"></label>
<input type="email" id="mail" name="user_mail" placeholder=" Email Address">
</div>
<div>
<label for="message"></label>
<textarea name="user_message" id="message" cols="30" rows="10" placeholder=" Let me know what's on your mind"></textarea>
</div>
<div class="sendButton">
<button class="btn" type="submit" disabled="disabled">Send</button>
</div>
</form>
and the Jquery which I have for now (I know it is not completed but I don't know how to do it)
$("input[type='text'], textarea").on("keyup", function () {
if ($(this).val() != "" && $("textarea").val() != "") {
$(".btn").removeAttr("disabled");
} else {
$(".btn").attr("disabled", "disabled");
}
});
I want a button (.btn) to change its background color to purple.
Of course, you can do it:
I would suggest controlling the colour of the button using a class on the containing form element. This will give you some flexibility to show or hide or restyle other content when the form is in it's incomplete state.
I've also used a css class to target the form fields that you want to check, in case you want fields that are optional.
You can call a
function()
in eachinput>keyup
(I preferinput
event), to check allinputs
were filled.Check https://fiddle.jshell.net/kgm3hs9k/4/
Hope it help.
Cheers
Working example:
The easy way is to check all the values on each change. It can be slow for very large forms, however:
Try this Give your input fields the same class in my case I gave it "mandatoryfields"
Script