I would like to insert 2 inputs into a td, today my code works with only one input, and even saves the information in the database, but I need to include one more input to enter a password to authorize the update. Today it looks like this:
A% w / w% Maturity
A%of%Value
Whenyouactuallywantedittolooklikethis,bothforthedateandthevalue.
Thecodeexamplefollows.
$(document).ready(function() {
$('#tabelaEditavel tbody tr').each(function(i) {
$(this).children('td').each(function(p) {
if (($(this).attr('title') === 'Valor') || $(this).attr('title') === 'Vencimento') {
$(this).dblclick(function() {
if ($('td > input').length > 0) {
return;
}
var conteudoOriginal = $(this).text();
var novoElemento = $('<input/>', {
type: 'text',
value: conteudoOriginal
});
//tentei adicionar o input abaixo mas não funcionou
var passWord = $('<input/>', {
type: 'text',
value: '1234'
});
if ($(this).attr('title') === 'Valor') {
$(novoElemento)
.maskMoney({
prefix: 'R$ ',
allowNegative: true,
thousands: '',
decimal: ',',
affixesStay: true
});
}
if ($(this).attr('title') === 'Vencimento') {
$(novoElemento)
.mask("99/99/9999");
}
$(this).html(novoElemento.bind('blur keydown', function(e) {
var keyCode = e.which;
var conteudoNovo = $(this).val();
if (keyCode == 13 || keyCode == 9 || keyCode == 0 && conteudoNovo != '' && conteudoNovo != conteudoOriginal) {
var objeto = $(this);
$.ajax({
type: "POST",
url: "#",
data: {
id: $(this).parents('tr').children().first().text(),
campo: $(this).parent().attr('title'),
valor: conteudoNovo
},
success: function(result) {
objeto.parent().html(conteudoNovo);
$('body').append(result);
}
});
var posicao = p + 1;
$(this).parent()
.html(conteudoNovo)
.parents('tr');
} else if (keyCode == 27 || e.type == 'blur')
$(this).parent().html(conteudoOriginal);
}));
$(this).children().select();
});
};
});
});
});
* {
font-family: Consolas
}
.tabelaEditavel {
border: solid 1px;
width: 100%
}
.tabelaEditavel td {
border: solid 1px;
}
.tabelaEditavel .celulaEmEdicao {
padding: 0;
}
.tabelaEditavel .celulaEmEdicao input[type=text] {
width: 100%;
border: 0;
background-color: rgb(255, 253, 210);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/jquery.maskedinput/1.4.1/jquery.maskedinput.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-maskmoney/3.0.2/jquery.maskMoney.min.js"></script><!DOCTYPEhtml><tableid="tabelaEditavel" class="tabelaEditavel">
<thead>
<tr>
<th>Código</th>
<th>Vencimento</th>
<th>Valor</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr id="1">
<td>001</td>
<td title="Vencimento">14/06/2018</td>
<td title="Valor">R$ 189,52</td>
<td><button>A pagar</button></td>
</tr>
<tr id="2">
<td>002</td>
<td title="Vencimento">18/06/2018</td>
<td title="Valor">R$ 7859,25</td>
<td><button>A pagar</button></td>
</tr>
<tr id="3">
<td>003</td>
<td title="Vencimento">21/06/2018</td>
<td title="Valor">R$ 78,59</td>
<td><button>A pagar</button></td>
</tr>
</tbody>
</table>