Sunday, 7 February 2016





You can generate unlimited textboxes and unlimited their sub-texboxes by using the below code..

HTML CODE


<input type='text' name=''></input> <input id='btnAdd' type='button' class='btn btn-primary' value='+' onclick='AddTextBox(".$duty_id[$x].")' />
<button onClick=\"toggle_visibility('watch');\">?</button> <div id='TextBoxContainer".$duty_id[$x]."'>
<!--Textboxes will be added here -->
</div>


 JAVASCRIPT CODE


function GetDynamicTextBox(value,id){
var counter='1';
return '<td></td><td><input name = "DynamicTextBox" type="text" value = "' + value + '" id="country'+ id +'" onkeyup="suggest(this.value,'+ id +')" /></td>' +
'<td><input type="button" value="-" class="btn btn-primary hide-print" id="rem_btn" onclick = "RemoveTextBox(this,'+ id +')" /></td>'

counter=counter + 1;
}

function AddTextBox(id) {
var div = document.createElement('DIV');
div.innerHTML = GetDynamicTextBox("",id);
document.getElementById("TextBoxContainer"+id).appendChild(div);
}

function RemoveTextBox(div,id) {
//alert(id);
document.getElementById("TextBoxContainer"+id).removeChild(div.parentNode);
}
For any query write me in comments or email me

0 comments:

Post a Comment

Hi to all Visitors,
Feel free to Comment Here.
Your Feedback or suggestion will be appreciated.