I want to dynamically add two textboxes and two dropdownlist through a button using jquery. i.e below
<tr>
<td align="center">
<table id="controls">
</table>
<%= button_tag "btnAdd"%>
</td>
</tr>
You can see above that i make a table where i want to add textboxes and dropdown and also I add button because when i click on button, then textboxes and dropdown will be added and below is jquery code:
<script type="text/javascript">
var k = 0, j = 0;
var year = new Date().getFullYear();
$(document).ready(function() {
$("#btnAdd").click(function() {
var field = $("#field").val();
var year = new Date().getFullYear();
var DDL_fromProfession = "<select name='ParametersFromProf' id='DDL_FromProYear'>";
for (var i = year; i >= 1950; --i) {
DDL_fromProfession += "<option text='" + i + "' value='" + i + "'>" + i + "</option>";
}
DDL_fromProfession += "</select>";
var DDL_ToProfession = "<select name='ParametersToProf' id='DDL_ToProYear'>";
for (var j = year; j >= 1950; --j) {
if (j != year) {
DDL_ToProfession += "<option text='" + j + "' value='" + j + "'>" + j + "</option>";
}
else {
DDL_ToProfession += "<option text='Present' value='Present'>Present</option>";
}
}
DDL_ToProfession += "</select>";
var newRow1 = "<tr><td align='center' style='font-size: large; color: #212121;' height='35px'>from"
+ DDL_fromProfession + " to " + DDL_ToProfession;
newRow1 += "<br/><button type='button' class='btn_rmv'>Remove</button></td></tr>";
var input = "<input name='parameters' id='field' type='text' value='Designation' style='text-align:center;' onblur='WaterMarkDesignation(this, event);' onfocus='WaterMarkDesignation(this, event);'/>";
var input1 = "<input name='parametersCompany' id='field' type='text' value='Company' style='text-align:center;' onblur='WaterMarkCompany(this, event);' onfocus='WaterMarkCompany(this, event);'/>"
var newRow = "<tr><td align='center' style='font-size: x-large; color: #212121;' height='35px'>"
+ input + " at " + input1 + "</td></tr>";
$('#controls').append(newRow);
$('#controls').append(newRow1);
return false;
});
});
</script>
But when I click on button, It would not show me textboxes and dropdowns, Why. Kindly suggest me, I am waiting for your reply. Thanks