|
|
|
Del Row แล้วต้องการให้สร้าง ID เรียงลำดับใหม่น่ะครับ มี Code ให้ดู |
|
|
|
|
|
|
|
Code (PHP)
<?
$year=date("y");
$month=date("m");
$pr_no_value="PR".$year."".$month."xxx";
$curdate=date("Y-m-d");
if(!isset($category_id)){$category_id="";}
?>
<SCRIPT src="http://code.jquery.com/jquery-2.1.1.js"></SCRIPT>
<center>
<form name="form1" method="post" action="">
<input type="hidden" name="action" value="insert">
<table width="90%" borderColor="#000000" bgColor="#CDF3FD" border="0" cellSpacing="0" cellPadding="1" >
<tr align = "right">
<td height = 25 align = "right">
| <img src="<?echo $CFG->wwwroot?>/image/add.jpg" height="15" width="15"></img> <a href="../pr/pr_config.php?mode=pr&action=add" >
<font face="Arial, Helvetica, sans-serif" size="2" ><b>Create PR</b></font>
</a>
| <img src="<?echo $CFG->wwwroot?>/image/magnifier.jpg" height="15" width="15"></img> <a href="../pr/pr_config.php?mode=pr&action=new">
<font face="Arial, Helvetica, sans-serif" size="2" ><b>Search PR</b></font>
</a> |
</td>
</tr>
</table>
<hr color = "#435ED4" style ="height:1px;" width="90%">
<table width="90%" border="1" cellspacing="0" cellpadding="1" bgcolor="#F0F0F2" bordercolor="#FFFFFF">
<tr bgcolor="#D1CFD5">
<td align="left" colspan="4">
<font face="Arial, Helvetica, sans-serif" size='3'><b> Create PR</b></font>
</td>
</tr>
<tr>
<td align="right">
<font face="Arial, Helvetica, sans-serif" ><b>PR Number :: </font></b>
</td>
<td align="left">
<input type="text" name="pr_no_show" id="pr_no_show" value="<?echo $pr_no_value;?>" readonly size="8">
</td>
<td align="right">
<font face="Arial, Helvetica, sans-serif" ><b>Request Date :: </font></b>
</td>
<td align="left" >
<input type="text" name="date_request" id="date_request" value="<?echo $curdate;?>" size="8">
<input type="hidden" name="curdate" id="curdate" value="<?echo $curdate;?>" size="8">
</td>
</tr>
<tr>
<td align="right">
<font face="Arial, Helvetica, sans-serif" ><b>Project Number :: </font></b>
</td>
<td align="left">
<input type="text" name="project_no" id="project_no" value="" readonly size="8">
</td>
<td align="right">
<font face="Arial, Helvetica, sans-serif" ><b>Project Name <font color="red">*</font> :: </font></b>
</td>
<td align="left">
<input type="text" name="project_name" id="project_name" value="" size="50">
</td>
</tr>
<tr>
<td align="right">
<font face="Arial, Helvetica, sans-serif" ><b>Subject Name <font color="red">*</font> :: </font></b>
</td>
<td align="left" colspan="3">
<input type="text" name="subject_name" id="subject_name" size="60">
</td>
</tr>
<tr>
<td align="right">
<font face="Arial, Helvetica, sans-serif" ><b>Location <font color="red">*</font> :: </font></b>
</td>
<td align="left" colspan="3">
<input type="text" name="location" id="location" size="50">
</td>
</tr>
<tr>
<td align="right">
<font face="Arial, Helvetica, sans-serif" ><b>Devices Name <font color="red">*</font> :: </font></b>
</td>
<td align="left" colspan="3">
<input type="text" name="device_name" id="device_name" size="50">
</td>
</tr>
<tr>
<td align="right">
<font face="Arial, Helvetica, sans-serif" ><b>Purpose <font color="red">*</font> :: </font></b>
</td>
<td align="left" colspan="3">
<input type="text" name="purpose" id="purpose" size="50">
</td>
</tr>
<tr>
<td align="right">
<font face="Arial, Helvetica, sans-serif" ><b>Supplier ID :: </font></b>
</td>
<td align="left">
<input type="text" name="supplier_id" id="supplier_id" value="" readonly size="8">
</td>
<td align="right">
<font face="Arial, Helvetica, sans-serif" ><b>Supplier Name <font color="red">*</font> :: </font></b>
</td>
<td align="left">
<input type="text" name="supplier_name_th" id="supplier_name_th" value="" size="50">
</td>
</tr>
<tr>
<td align="right">
<font face="Arial, Helvetica, sans-serif" ><b>Payment :: </font></b>
</td>
<td align="left" colspan="3">
<input type="text" name="payment" id="payment" size="8" readonly>
</td>
</tr>
<tr>
<td align="right">
<font face="Arial, Helvetica, sans-serif" ><b>Final Date <font color="red">*</font> :: </font></b>
</td>
<td align="left" colspan="3">
<input type="text" name="date_final" id="date_final" value="" size="8">
</td>
</tr>
<tr>
<td align="right">
<font face="Arial, Helvetica, sans-serif" ><b>Remarks :: </font></b>
</td>
<td align="left" colspan="3">
<textarea rows="3" cols="100" name="remarks_budget" id="remarks_budget" value=""></textarea>
</td>
</tr>
<tr>
<td align="right">
<font face="Arial, Helvetica, sans-serif" ><b>Status :: </font></b>
</td>
<td align="left" colspan="3">
<select name="status_pr" id="status_pr">
<option value="all">=Choose=</option>
<?//select_status($status_pr=1);?>
</select>
</td>
</tr>
<tr bgcolor="#8E8C8C">
<td align="center" colspan="4">
<font face="Arial, Helvetica, sans-serif" size='3'><b>Order details</b></font>
</td>
</tr>
</table>
<body>
<table id="mytbl" width="90%" border="1" cellspacing="0" cellpadding="1" bgcolor="#F0F0F2" bordercolor="#FFFFFF">
<thead>
<tr>
<td align="center" nowrap><font face="Arial, Helvetica, sans-serif" ><b>No</b></font></td>
<td align="center" nowrap><font face="Arial, Helvetica, sans-serif" ><b>Category type <font color="red">*</font></b></font></td>
<td align="center" nowrap><font face="Arial, Helvetica, sans-serif" ><b>Sub Category <font color="red">*</font></b></font></td>
<td align="center" nowrap><font face="Arial, Helvetica, sans-serif" ><b>Name Product <font color="red">*</font></b></font></td>
<td align="center" nowrap><font face="Arial, Helvetica, sans-serif" ><b>Unit <font color="red">*</font></b></font></td>
<td align="center" nowrap><font face="Arial, Helvetica, sans-serif" ><b>Quality <font color="red">*</font></b></font></td>
<td align="center" nowrap><font face="Arial, Helvetica, sans-serif" ><b>Price <font color="red">*</font></b></font></td>
<td align="center" nowrap><font face="Arial, Helvetica, sans-serif" ><b>Total</b></font></td>
<td align="center" nowrap><div style="margin:5px auto 0px auto;"><input type="button" id="add_item"></div></td>
</tr>
</thead>
<input type="hidden1" name="row_add" id="row_add" value="1">
<tbody id="tbody">
<!--show data when press + -->
<?$row=1;?>
<tr>
<td align='center'><span class='span_id'><?echo $row=1;?>.</td>
<td align="center">
<select name="category_id[]" id="category_id<?echo $row;?>" onchange="change_category(<?echo $row;?>);">
<option value='all'>=========Choose=========</option>
<?//select_category($category_id);?>
</select>
</td>
<td align="center">
<input type='hidden1' name="sub_category_id[]" id="sub_category_id<?echo $row;?>" value="">
<input type="hidden1" name="sub_category_name_old[]" id="sub_category_name_old<?echo $row;?>" value="">
<input type="text" name="sub_category_name[]" id="sub_category_name<?echo $row;?>" value="" size="30" disabled>
</td>
<td align="center">
<input type='hidden1' name="product_id[]" id="product_id<?echo $row;?>" value="">
<input type="hidden1" name="product_name_old[]" id="product_name_old<?echo $row;?>" value="">
<input type="text" name="product_name[]" id="product_name<?echo $row;?>" value="" size="30" disabled>
</td>
<td align="center">
<select name="unit_id[]" id="unit_id<?echo $row;?>">
<option value="all">=========Choose=========</option>
<?//select_unit($unit_id);?>
</select>
</td>
<td align="center">
<input type="text" style="text-align:right;" name="quality[]" id="quality<?echo $row;?>" value="" size="2">
</td>
<td align="center">
<input type="text" style="text-align:right;" name="price[]" id="price<?echo $row;?>" value="" size="5">
</td>
<td align="center">
<input type="text" style="text-align:right;" name="total[]" id="total<?echo $row;?>" size="5" value="" readonly>
</td>
<td align="center"><!--<img id="del1" rel="1" src="../image/minus.png" height="20" width="20"></img>--></td>
</tr>
</tbody>
<tr>
<td align="right" colspan="6">
<font face="Arial, Helvetica, sans-serif" ><b>Summary </font></b>
</td>
<td align="right" colspan="2">
<input type="text" style='text-align:right;' name="summary" id="summary" size="15" readonly value="">
</td>
</tr>
</table>
</body>
<table width="90%" border="1" cellspacing="0" cellpadding="1" bgcolor="#F0F0F2" bordercolor="#FFFFFF">
<tr bgcolor="#F3ECC7">
<td align="right">
<font face="Arial, Helvetica, sans-serif" ><b>Useradd :: </font></b>
</td>
<td align="left" colspan="3"> <?echo $user;?></td>
</tr>
<tr bgcolor="#F3ECC7">
<td align="right">
<font face="Arial, Helvetica, sans-serif" ><b>Adddate :: </font></b>
</td>
<td align="left" colspan="3"> </td>
</tr>
<tr bgcolor="#F3ECC7">
<td align="right">
<font face="Arial, Helvetica, sans-serif" ><b>Addtime :: </font></b>
</td>
<td align="left" colspan="3"> </td>
</tr>
<tr bgcolor="#F3ECC7">
<td align="right">
<font face="Arial, Helvetica, sans-serif" ><b>Last Update :: </font></b>
</td>
<td align="left" colspan="3"> </td>
</tr>
</table>
<table>
<tr>
<td colspan="2" align="right">
<input type="submit" name="submit" value=" Add " onclick="return check_submit();">
<input type="reset" name="reset" value="Cancle">
</td>
</tr>
</table>
</form>
</center>
<script type="text/javascript">
$(document).ready(function(){
//add row
$('#add_item').click(function(){
row = $('#tbody tr').length+1;
var tmp;
for(i=1;i<=row;i++){
tmp="<tr>";
tmp+="<td align='center'><span class='span_id'>"+i+"</td>";
tmp+="<td align='center'></td>";
tmp+="<td align='center'></td>";
tmp+="<td align='center'></td>";
tmp+="<td align='center'></td>";
tmp+="<td align='center'></td>";
tmp+="<td align='center'><input type='text' style='text-align:right;' name='price[]' id='price"+i+"' value='' size='5'></td>";
tmp+="<td align='center'><input type='text' style='text-align:right;' name='total[]' id='total"+i+"' size='5' value='' readonly></td>";
//del
tmp+="<td align='center'><input type='button' value='-' id='del'></td>";
tmp+="</tr>";
}
$('#tbody').append($(tmp));
});
});
$('#tbody').on('click','#del',function(){
if(confirm('Confirm to delete row?')){
$(this).closest("tr").remove();
}
});
</script>
จาก Code ด้านบนสามารถ Copy แล้วทำการรันได้เลยน่ะครับ คือ ผมต้องการอย่างนี้น่ะครับ id ของ price , total ใน javascript ตอน add row มาจะมี ลำดับดังนี้ price1 , price2 , price3
ถ้าผมทำการลบ price2 ทิ้งไป ผมอยากให้ price3 เปลี่ยนค่าเป็น price2 น่ะครับ
แต่ตอนนี้ มันจะเป็น price1 , price3 ในกรณีที่ลบ price2
ครับ
Tag : PHP
|
|
|
|
|
|
Date :
2014-10-06 15:21:48 |
By :
nut_ch31 |
View :
807 |
Reply :
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
หลังกด + - ให้รัน อันนี้
Code (JavaScript)
i=1;
$('#mytbl tr .span_id').each(function(){
$(this).text(i)
i++;
})
|
ประวัติการแก้ไข 2014-10-06 15:58:43
|
|
|
|
Date :
2014-10-06 15:55:02 |
By :
gaowteen |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
แล้วที่ผมให้ไปมันผิดตรงไหนเหรอครับ id คือ colum No ใช้ไหมครับ พอกด + - แล้วก็รันที่ผมให้ไป มันก็ จะได้ เลขแถวใหม่ ไม่ถูกเหรอครับ
|
|
|
|
|
Date :
2014-10-06 16:44:01 |
By :
gaowteen |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
tmp+="<td align='center'><input type='text' style='text-align:right;' name='price[]' id='price"+i+"' value='' size='5'></td>";
278.tmp+="<td align='center'><input type='text' style='text-align:right;' name='total[]' id='total"+i+"' size='5' value='' readonly></td>";
279.//del
ต้องการให้รัน ตรงนี้ใหม่จ๊าาาาาา ตรงตัว +i+ จ๊ะ
|
|
|
|
|
Date :
2014-10-06 16:55:56 |
By :
nut_ch31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เอาไปต่อยอกเองนะครับ
Code (JavaScript)
i=1;
$('#mytbl tbody tr').each(function(){
$(this).find('input[name="price[]"]').val(i)
//$(this).find('input[name="price[]"]').attr('id','price'+i)
i++;
})
|
|
|
|
|
Date :
2014-10-06 17:04:29 |
By :
gaowteen |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณครับ
$(this).find('select[name="unit_id[]"]').attr('id','unit_id'+i);
$(this).find('input[name="quality[]"]').attr('id','quality'+i);
$(this).find('input[name="price[]"]').attr('id','price'+i);
ว่าเเต่ผมติดที่ว่าตอนลบเเล้วค่า row ที่วนหาไม่ยอมเปลี่ยนตอนส่งค่าไป onchange ตามรูปครับ
|
|
|
|
|
Date :
2014-10-07 10:36:50 |
By :
nut_ch31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|