The following code was implemented from a question that I found here in the system
$('form input[type="text"]').on('input', function() {
var inputempty = false;
$('form > input').each(function() {
if($(this).val() == '') {
inputempty = true; } });
if(inputempty) {
$('form input[type="submit"]').attr('style', 'background: red');
} else {
$('form input[type="submit"]').removeAttr('style'); } });
The problem is that I can not get it to read all inputs inside the form, it can only detect the first input, I'm using jquery 1.8.3 and jquery ui 1.11.4
follows html structure
<form action="<?php echo htmlspecialchars($siteuri); ?>" method="post">
<input type="text" name="contacts_form_name" placeholder="Nome do contato" autofocus />
<input type="text" name="contacts_form_a[1]" placeholder="Nome do campo" tabindex="1" />
<input type="text" name="contacts_form_b[1]" placeholder="Valor do campo" tabindex="2" />
<div id="contacts_form">
Aqui dentro são inseridos inputs com jquery
</div>
<div id="contacts_form_add" class="cursor_pointer">+</div>
<input class="cursor_pointer" type="submit" name="contact_send" value="Salvar" />
</form>
and follow the jquery
var scntDiv = $('#contacts_form');
var rscn = $('#contacts_form x').size() + 1;
$('#contacts_form_add').live('click', function() {
$('<x><input type="text" id="focus' + rscn +'" name="contacts_form_a[' + rscn +']" placeholder="Nome do campo" /><input type="text" name="contacts_form_b[' + rscn +']" placeholder="Valor do campo" /><span id="contacts_form_rem" class="cursor_pointer">X</span></x>').appendTo(scntDiv);
$('#focus'+ rscn).focus();
rscn++;
inputattr();
return false; });
$('#contacts_form_rem').live('click', function() {
if(rscn > 1) {
$(this).parents('x').remove();
rscn--; }
return false; });