I check every required field on the form. I tried this, but it only works for the first input. How can I make it work for every input?
if($('[required]').val() != ''){
$('.button1').fadeIn(0);
$('.button2').fadeOut(0);
}else{
$('.button1').fadeOut(0);
$('.button2').fadeIn(0);
}
EDIT : for more context, here is another function that I used below to apply when they change, and HTML code.
$('[required]').change(function() {
if($('[required]').val() != ''){
$('.button1').fadeIn(0);
$('.button2').fadeOut(0);
}else{
$('.button1').fadeOut(0);
$('.button2').fadeIn(0);
}
});
HTML
I have a set of such inputs:
<input type="text" id="title" name="title" value="" required>
<input type="text" id="size" name="size" value="" required>
<input type="text" id="length" name="length" value="" required>
:
<a class="button1" style="display:none" >button 1</a>
<a class="button2">button 2</a>
So, I want to check the empty fields when the page loads and when they change.
By the way, I do not have a form tag, because it is for mobile devices and did not think that it is really necessary, if that matters.
Thanks again!
source
share