เงื่อนไขการ show/hide textbox มาให้กรอกข้อมูล ในการ clone หลายแถว
ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา เงื่อนไขการ show/hide textbox มาให้กรอกข้อมูล ในการ clone หลายแถว
เงื่อนไขการ show/hide textbox มาให้กรอกข้อมูล ในการ clone หลายแถว
Copy

ตามรูปนะคะ คือ เวลาเลือก select ประเภท = เช่า จะขึ้น textbox ระยะเวลาการเช่า มาให้กรอกข้อมูล
แต่พอกดปุ่ม บวก เพื่อจะเพิ่มสินค้าอีกตัว ยังไม่ทันเลือกประเภท มันก็ clone ตัว textbox มาด้วยค่ะ
codeการ clone
<script language="JavaScript">
$(document).ready(function(){
$("#addRow").click(function(){
var html = $(".tramount:last").html();
var last_id = parseInt($(".tramount:last").attr("id").split("_")[1]);
var new_id = last_id+1;
var newRow = '<tr class="tramount" id="tramount_'+new_id+'">';
newRow += html.replace(new RegExp("_"+last_id,"g"), "_"+new_id);
newRow += "</tr>";
$("#tblamount tbody").append(newRow);
});
$("#removeRow").click(function(){
if($(".tramount").length > 1) $(".tramount:last").remove()
});
$('input[name="cost[]"], input[name="amount[]"]').change(function(){
var total = 0.0;
$(".tramount").each(function(){
var now_id = parseInt($(this).attr("id").split("_")[1]);
var cnt = parseInt($("#amount_"+now_id).val());
var price = parseFloat($("#cost_"+now_id).val());
var row = (cnt*price);
if(row!= NaN && row>0) total += row;
});
$("#sum").val(total);
});
});
</script>
code การ show/hide textbox
<script language="javascript">
$(document).ready(function() {
$('#rentPrice').hide(); //hide field on start
$('#type_1').change(function() {
var $index = $('#type_1').index(this);
if($('#type_1').val() == 'เช่า') { //if this value is NOT selected
$('#rentPrice').show(); //this field is hidden
}
else {
$('#rentPrice').hide();//else it is shown
}
});
});
</script>
อยากรู้ว่าจะทำยังไง ให้ไม่ clone มาทั้งหมดค่ะ ให้โชว์ textbox เฉพาะตอนเลือก select ประเภท = เช่า เท่านั้น คำแนะนำ และการใช้งาน
สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก
- ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
เว็บไซต์ของเราให้บริการเนื้อหาบทความสำหรับนักพัฒนา โดยพึ่งพารายได้เล็กน้อยจากการแสดงโฆษณา
โปรดสนับสนุนเว็บไซต์ของเราด้วยการปิดการใช้งานตัวปิดกั้นโฆษณา (Disable Ads Blocker) ขอบคุณครับ