Reputation: 41
I have a form something like,
<form>
<table>
<tr>
<td>
Date <input type="text" name="date" id="date">
</td>
<td>
Installment <input type="text" name="installment" id="installment">
</td>
<td>
Balance <input type="text" name="balance" id="balance">
</td>
</tr>
</form>
The Thing I want is that to auto generate these fields of form when the value of the field name="balance" exceeds zero.
if you guys have any idea. Please answer me. Thanks in advance.
Upvotes: 0
Views: 1693
Reputation: 4615
You have two options for implementing this.
You can create the fields in the server-side but set its display:none
. When the value of the balance test field is greater than 0
set the display:none
Or you can create the fields from the JavaScript itself
I have written a sample code(assuming you are using jquery)
$(document).ready(function () {
$('#balance').change(function() {
if($(this).val() > 0)
{
$('<input>').attr({
type: 'text',
name: 'date',
id: 'date'
}).appendTo($("#formId"));
$('<input>').attr({
type: 'text',
name: 'installment',
id: 'installment'
}).appendTo($("#formId"));
}
else
{
$('#date').remove();
$('#installment').remove();
}
});
$('#removeRow').click(function() {
$('#date').remove();
$('#installment').remove();
});
});
[EDIT] : included the code to remove the row
Upvotes: 1