:wanwan017:
ช่วยด้วยครับ :wanwan017:
(https://lh6.googleusercontent.com/-S_snD0ICyWc/UqWIxk0B9kI/AAAAAAAAD9Y/sky4JOW4Kj0/w849-h98-no/add-search.JPG)
ผมพยายามจะสร้างการเพิ่มสินค้าแบบหาสินค้าจากการพิมพ์เพียงช่องเดียว ตามภาพครับ
แต่มีปัญหาตรงที่พอ คลิก Add Button กลับขึ้น Undefined แล้วก็ค้นหาไม่ได้ครับ
Codeน่ะครับ
code การเพิ่ม Textbox
<script type="text/javascript">
$(document).ready(function(){
var counter = 2;
$("#addButton").click(function () {
if(counter>30){
alert("Only 30 textboxes allow");
return false;
}
var newTextBoxDiv = $(document.createElement('tr'))
.attr("id", 'TextBoxDiv' counter);
newTextBoxDiv.after().html('<td><input name="code_item' counter '" id="show_id' counter '" size="15" value="" disabled /></td>'
'<td><input name="desc' counter '" type="text" id="show_desc' counter '" size="50" />'
make_autocom("show_desc1","show_id1") '</td>'
'<td align="center"><input name="unit' counter '" type="text" id="show_unit' counter '" disabled /></td>'
'<td align="center"><input type="number" name="std' counter '" id="show_std' counter '" min="1" max="999" /></td>'
'<td><input type="number" name="qty' counter '" id="show_qty' counter '" min="1" max="999" /></td>'
'<td class="block"> </td><td class="block"> </td>');
newTextBoxDiv.appendTo("#TextBoxesGroup");
counter ;
});
$("#removeButton").click(function () {
if(counter==1){
alert("No more textbox to remove");
return false;
}
counter--;
$("#TextBoxDiv" counter).remove();
});
$("#getButtonValue").click(function () {
var msg = '';
for(i=1; i<counter; i ){
msg = "
show_id #" i " : " $('#show_id' i).val();
}
alert(msg);
});
});
</script>
code การค้นหา
<script type="text/javascript" src="../js/autocomplete.js"></script>
<script type="text/javascript">
function make_autocom(autoObj,showObj){
var mkAutoObj=autoObj;
var mkSerValObj=showObj;
new Autocomplete(mkAutoObj, function() {
this.setValue = function(id) {
document.getElementById(mkSerValObj).value = id;
}
if ( this.isModified )
this.setValue("");
if ( this.value.length < 1 && this.isNotClick )
return ;
return "../js/gdata.php?q=" encodeURIComponent(this.value);
});
}
</script>
Code การเรียกใช้
<table id='TextBoxesGroup'>
<tr id="TextBoxDiv1">
<td align="center">
<input name="code_item1" id="show_id1" size="15" value="" disabled />
</td>
<td>
<input name="desc1" type="text" id="show_desc1" size="50" />
<script type="text/javascript">
make_autocom("show_desc1","show_id1");
</script>
</td>
<td align="center">
<input name="unit1" type="text" id="show_unit1" disabled />
</td>
<td align="center">
<input type="number" name="std1" id="show_std1" min="1" max="999" />
</td>
<td>
<input type="number" name="qty1" id="show_qty1" min="1" max="999" />
</td>
<td class="block"> </td>
<td class="block"> </td>
</tr>
</table>
<input type='button' value='Add Button' id='addButton'>
<input type='button' value='Remove Button' id='removeButton'>
<input type='button' value='Get TextBox Value' id='getButtonValue'>
รบกวนด้วยครับ :wanwan017: