<script language="Javascript" type="text/javascript">
<!--
//Add more fields dynamically.
function addField(area,field1,field2,limit) {
if(!document.getElementById) return; //Prevent older browsers from getting any further.
var field_area = document.getElementById(area);
var all_inputs = field_area.getElementsByTagName('input'); //Get all the input fields in the given area.
//Find the count of the last element of the list. It will be in the format '<field><number>'. If the
// field given in the argument is 'friend_' the last id will be 'friend_4'.
var last_item = all_inputs.length - 1;
var last = all_inputs[last_item].id;
var count = Number(last.split("_")[1]) + 1;
if(count > limit && limit > 0) return;
field_area.innerHTML += "<li><?=$text_add?><input name='"+(field1+count)+"' id='"+(field1+count)+"' type='<?=$type_input?>' /> CIName ใหม่<input name='"+(field2+count)+"' id='"+(field2+count)+"' type='text' /> <a style=\"cursor:pointer;color:blue;\" onclick=\"this.parentNode.parentNode.removeChild(this.parentNode);\">Remove Field</a></li>";
}
//-->
</script>
<form name="frm" method="post" action="">
<strong>CIName</strong><br />
<ol id="CIName">
<li><?=$text_add?><input type=<?=$type_input?> name="CIOld_1" id="CIOld_1" /> CIName ใหม่<input type="text" name="CINew_1" id="CINew_1" /></li>
</ol>
<input id="add_ci" name="add_ci" type="button" value="+" onclick="addField('CIName','CIOld_','CINew_',<?=$amount?>);" />
<br /><br />
<input type="submit" name="submit_save" id="submit_save" value="Save" />
</form>
ตามรูปที่ผมทำ เวลาผมใส่ข้อมูลใน text field ไปแล้ว พอผมกด + ข้อมูลมันก็จะหายไปหมด
ผมอยากทำให้ข้อมูลไม่หายเวลากด + ทำยังไงครับ
Code (JavaScript)
function addField(area,field1,field2,limit)
{
if (!document.getElementById) return; //Prevent older browsers from getting any further.
var field_area = document.getElementById(area);
var all_inputs = field_area.getElementsByTagName('input'); //Get all the input fields in the given area.
//Find the count of the last element of the list. It will be in the format '<field><number>'. If the
// field given in the argument is 'friend_' the last id will be 'friend_4'.
var last_item = all_inputs.length - 1;
var last = all_inputs[last_item].id;
var count = Number(last.split("_")[1]) + 1;
if (count > limit && limit > 0) return;
field_area.innerHTML += "<li><?=$text_add?><input name='"+(field1+count)+"' id='"+(field1+count)+"' type='<?=$type_input?>' /> CIName ใหม่<input name='"+(field2+count)+"' id='"+(field2+count)+"' type='text' /> <a style=\"cursor:pointer;color:blue;\" onclick=\"this.parentNode.parentNode.removeChild(this.parentNode);\">Remove Field</a></li>";
}