Example of dynamically adding, deleting rows, and adding an onkeyup table using js

Source: Internet
Author: User

Copy codeThe Code is as follows:
<% @ Page language = "java" contentType = "text/html; charset = UTF-8"
PageEncoding = "UTF-8" %>
<% @ Taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %>
<! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd">
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
<Title> shipping application </title>
<Script type = "text/javascript">
Function countTotalRealPrice (){
Var productNeedNum = $ ("# productNeedNum"). val ();
Var realPrice = $ ("# realPrice"). val ();
Var totalRealPrice = productNeedNum * realPrice;
$ ("# TotalRealPrice"). val (totalRealPrice );

}
Function countTotalTicketPrice (){
Var productNeedNum = $ ("# productNeedNum"). val ();
Var ticketPrice = $ ("# ticketPrice"). val ()
Var totalTicketPrice = productNeedNum * ticketPrice;
$ ("# TotalTicketPrice"). val (totalTicketPrice );
}

$ (Function (){
$ ("# T1" ).css ("display", "none ");
$ ("# T2" ).css ("display", "none ");
$ ("# T3" ).css ("display", "none ");
$ ("# T4" ).css ("display", "none ");
$ ("# T5" ).css ("display", "none ");

});
/* Function sumNum (){
$ ("Input [name = productNeedNum]"). each (function (){
// Alert ($ (this). attr ("id"); // each id
Var productNeedNum = $ ("# productNeedNum"). attr ("value ")
Alert (productNeedNum );
// Var sum + = productNeedNum;
// Alert ("sum:" + sum );
// $ ("# Sum"). val (sum );
});

}*/

Function addRow (){
Var x = document. getElementById ('tb1 '). insertRow (3 );
Var a = x. insertCell (0)
Var B = x. insertCell (1)
Var c = x. insertCell (2)
Var d = x. insertCell (3)
Var e = x. insertCell (4)
Var f = x. insertCell (5)
Var g = x. insertCell (6)
Var h = x. insertCell (7)
Var a1 = "<select id = 'produd d' name = 'produd d' style = 'width: 140px; height: 22px; text-align: center; '> <c: forEach items = '$ {productIdNames}' var = 'P'> <option value = '$ {p. productId} '> $ {p. commName} </option> </c: forEach> </select> ";
Var b1 = "<select id = 'typename' name = 'typename' style = 'width: 140px; height: 22px; text-align: center; '> <c: forEach items = '$ {typeInfos}' var = 'ti'> <option value = '$ {ti. typeId} '>$ {ti. typeName} </option> </c: forEach> </select> ";
Var c1 = "<select id ='' name = ''style = 'width: 70px; height: 22px; text-align: center; '> <option value = '0'> box </option> <option value = '1'> bottle </option> </select> ";
Var d1 = "<input onkeyup = 'sum (this. id) 'name = 'productneednum' id = 'productneednum' type = 'text' style = 'width: 89%; height: 18px 'value = '0'/> ";
Var e1 = '<input onkeyup = "sum (this. id) "name =" realPrice "id =" realPrice "type =" text "style =" width: 89%; height: 18px; "value =" 0 "/> ';
Var f1 = '<input onkeyup = "sum (this. id) "name =" ticketPrice "id =" ticketPrice "type =" text "style =" width: 91%; height: 18px; "value =" 0 "/> ';
Var g1 = '<input name = "totalRealPrice" id = "totalRealPrice" type = "text" style = "width: 92%; height: 18px; "value =" 0 "/> ';
Var h1 = "<input name = 'totalticketprice' id = 'totalticketprice' type = 'text' style = 'width: 92.5%; height: 18px; 'value = '0'/> ";
A. innerHTML = a1
B. innerHTML = b1
C. innerHTML = c1
D. innerHTML = d1
E. innerHTML = e1
F. innerHTML = f1
G. innerHTML = g1
H. innerHTML = h1
}
Function deleteRow (){
Var tab = document. getElementById ('tb1 ');
If (tab. rows. length> 4)
{
Tab. deleteRow (tab. rows. length-2 );
} Else {
AlertMsg. confirm ("the last row is left and cannot be deleted! ");
}
}

Function sum (x ){
Var y = document. getElementById (x). value;
If (isNaN (y )){
Document. getElementById (x). value = 0;
}
Var num = document. getElementById ("productNeedNum"). value;
Var realPrice = document. getElementById ("realPrice"). value;
Var ticketPrice = document. getElementById ("ticketPrice"). value;
Var total = 0;
If (realPrice! = Null ){
Total = num * realPrice;
Document. getElementById ("totalRealPrice"). value = total;
}
If (ticketPrice! = Null ){
Total = num * ticketPrice;
Document. getElementById ("totalTicketPrice"). value = total;
}

}
</Script>
</Head>
<Body>
<Form id = "form1" method = "post" action = "$ {basePath}/sale/deliverSaleApply" class = "pageForm required-validate" onsubmit = "return validateCallback (this, navTabAjaxDone) ">
<Div class = "pageFormContent nowrap" layoutH = "56">
<Div style = "text-align: center; top: 90px; position: relative;">
<Table width = "752" border = "1px;" align = "center" style = "border-collapse: collapse; border: 1px solid black; margin: auto;">
<Tr height = "20px;">
<Td style = "width: 180px; height: 20px; vertical-align: middle"> applicant:
<Input name = "fullName" id = "fullName" type = "text" value = "$ {user. fullName}" disabled = "true"/>
</Td>
<Td width = "100" align = "left"> region:
<Select id = "areaId" name = "areaId">
<C: forEach items = "$ {areaTypes}" var = "a">
<Option value = "$ {a. areaId}" >$ {a. areaName} </option>
</C: forEach>
</Select>
</Td>
<Td width = "180" align = "left"> application date:
<Input name = "applyDate" id = "applyDate" type = "text" class = "date textInput readonly" style = "width: 40%" readonly = "readonly"/>
<A class = "inputDateButton" href = "javascript:;"> select </a>
</Td>
<Td style = "width: 288px; height: 20px; vertical-align: middle"> business type:
<Input type = "radio" name = "serviceId" id = "" value = "0" checked = "checked"/> instant release
<Input type = "radio" name = "serviceId" id = "" value = "1"/> instant release
<Input type = "radio" name = "serviceId" id = "" value = "2"/> others
</Td>
</Tr>
</Table>
<Table width = "752" border = "1px;" align = "center" style = "border-collapse: collapse; border: 1px solid black; margin: auto;">
<Tr>
<Td width = "121" height = "18px;"> full name of recipient </td>
<Td width = "615"> <input name = "fullName" id = "fullName" type = "text" style = "width: 99%; height: 20px; "/> </td>
</Tr>
</Table>
<Table width = "752" border = "1px;" align = "center" style = "border-collapse: collapse; border: 1px solid black; margin: auto; "id =" tb1 ">
<Tr>
<Td width = "54" rowspan = "80"> request delivery details </td>
<Td width = "82" rowspan = "2" height = "40px;"> product name </td>
<Td width = "65" rowspan = "2"> type </td>
<Td colspan = "2"> quantity </td>
<Td colspan = "2"> unit price </td>
<Td colspan = "2"> Settlement Loan </td>
</Tr>
<Tr>
<Td width = "54"> box/bottle </td>
<Td width = "53"> parts </td>
<Td width = "56"> real price (RMB) </td>
<Td width = "63"> fare (RMB) </td>
<Td width = "72" onclick = "deleteRow ()"> total real price (RMB) </td>
<Td width = "85" onclick = "addRow ()"> total fare (RMB) </td>
</Tr>
<Tr id = "a1">
<Td height = "20px;">
<Select id = "productId" name = "productId" style = "width: 140px; height: 22px; text-align: center;">
<C: forEach items = "$ {productIdNames}" var = "p">
<Option value = "$ {p. productId}" >$ {p. commName} </option>
</C: forEach>
</Select>
</Td>
<Td>
<Select id = "typeName" name = "typeName" style = "width: 140px; height: 22px; text-align: center;">
<C: forEach items = "$ {typeInfos}" var = "ti">
<Option value = "$ {ti. typeId}" >$ {ti. typeName} </option>
</C: forEach>
</Select>
</Td>
<Td>
<Select id = "" name = "" style = "width: 70px; height: 22px; text-align: center;">
<Option value = "0"> box </option>
<Option value = "1"> bottle </option>
</Select>
</Td>
<Td> <input name = "productNeedNum" id = "productNeedNum" type = "text" style = "width: 89%; height: 18px; "value =" 0 "onkeyup =" sum (this. id) "/> </td>
<Td> <input name = "realPrice" id = "realPrice" type = "text" style = "width: 89%; height: 18px; "value =" 0 "onkeyup =" sum (this. id) "/> </td>
<Td> <input name = "ticketPrice" id = "ticketPrice" type = "text" style = "width: 91%; height: 18px; "value =" 0 "onkeyup =" sum (this. id) "/> </td>
<Td> <input name = "totalRealPrice" id = "totalRealPrice" type = "text" style = "width: 92%; height: 18px; "value =" 0 "/> </td>
<Td> <input name = "totalTicketPrice" id = "totalTicketPrice" type = "text" style = "width: 92.5%; height: 18px; "value =" 0 "/> </td>
</Tr>
<Tr>
<Td> total </td>
<Td height = "18px;"> </td>
<Td> </td>
<Td> </td>
<Td> </td>
<Td> </td>
<Td> </td>
<Td> </td>
</Tr>
</Table>
<Table width = "752" border = "1px;" align = "center" style = "border-collapse: collapse; border: 1px solid black; margin: auto;">
<Tr>
<Td width = "91" height = "30px;"> settlement/payment method </td>
<Td colspan = "7">
<Input type = "radio" name = "pay" id = "" checked = "checked" value = "0"/>
<Input type = "radio" name = "pay" id = "" value = "1"/> private
<Input type = "radio" name = "pay" id = "" value = "2"/> non-active
</Td>
</Tr>
<Tr>
<Td rowspan = "3"> shipping info </td>
<Td width = "68" height = "18px;"> delivery method </td>
<Td width = "36">
<Select id = "sendType" name = "sendType" style = "width: 70px; height: 25px;">
<Option value = "0"> post </option>
<Option value = "1"> Shentong </option>
<Option value = "2"> others </option>
</Select> </td>
<Td width = "73"> start time of delivery </td>
<Td width = "100"> <input name = "accessionDate" id = "accessionDate" type = "text" class = "date textInput readonly" style = "width: 76%; height: 18px; "readonly =" readonly "/>
<A class = "inputDateButton" href = "javascript:;"> select </a> </td>
<Td colspan = "3">
<Input type = "radio" name = "priorityFlag" id = "common" checked = "checked" value = "0"/> common parts
<Input type = "radio" name = "priorityFlag" id = "urgency" value = "1"/> urgent
</Td>
</Tr>
<Tr>
<Td height = "18px;"> shipping address </td>
<Td colspan = "6"> <input name = "recvAddr" id = "recvAddr" type = "text" style = "width: 99%; height: 20px; "/> </td>
</Tr>
<Tr>
<Td height = "18px;"> arrival </td>
<Td> <input name = "arriveAddr" id = "arriveAddr" type = "text" style = "width: 91%; height: 20px;"/> </td>
<Td> receiver </td>
<Td> <input name = "recvPerson" id = "recvPerson" type = "text" style = "width: 94%; height: 20px;"/> </td>
<Td width = "73"> Contact Information </td>
<Td colspan = "2"> <input name = "contactPhone" id = "contactPhone" type = "text" style = "width: 97.7%; height: 20px; "/> </td>
</Tr>
<Tr>
<Td rowspan = "2"> approval </td>
<Td colspan = "2" height = "18px;"> General Manager's Office </td>
<Td colspan = "2"> marketing department </td>
<Td colspan = "3"> region </td>
</Tr>
<Tr>
<Td colspan = "2" height = "20px;">
<Input type = "radio" id = "" name = "approvalTwo" checked = "checked" value = "0"/> disagree
<Input type = "radio" id = "" name = "approvalTwo" value = "1" disabled = "true"/> agree
</Td>
<Td colspan = "2">
<Input type = "radio" id = "" name = "approvalOne" checked = "checked" value = "0"/> disagree
<Input type = "radio" id = "" name = "approvalOne" value = "1" disabled = "true"/> agree
</Td>
<Td colspan = "3">
<Input type = "radio" id = "" name = "approvalThree" checked = "checked" value = "0"/> disagree
<Input type = "radio" id = "" name = "approvalThree" value = "1" disabled = "true"/> agree
</Td>
</Tr>
</Table>
<Table width = "752" border = "1px;" align = "center" style = "border-collapse: collapse; border: 1px solid black; margin: auto; "id =" t1 ">
<Tr>
<Td width = "398" height = "30px;"> enter the following information by the marketing department/Finance Department </td>
</Tr>
</Table>
<Table width = "752" border = "1px;" align = "center" style = "border-collapse: collapse; border: 1px solid black; margin: auto; "id =" t2 ">
<Tr>
<Td width = "96" rowspan = "4"> loan payment </td>
<Td width = "96" height = "30px;"> accounting time </td>
<Td width = "179"> account/card number </td>
<Td width = "85"> recorded amount </td>
<Td colspan = "2"> operator </td>
</Tr>
<Tr>
<Td height = "30px;"> <input name = "recvTime" id = "recvTime" type = "text" class = "date textInput readonly" style = "width: 81%; height: 24px; "readonly =" readonly "/>
<A class = "inputDateButton" href = "javascript:;"> select </a> </td>
<Td> <input name = "cardNo" id = "cardNo" type = "text" style = "width: 97.2%; height: 24px;"/> </td>
<Td> <input name = "balance" id = "balance" type = "text" style = "width: 94.9%; height: 24px;"/> </td>
<Td width = "57"> <input disabled = "true" name = "dealPerson" id = "dealPerson" type = "text" style = "width: 93%; height: 24px; "value =" $ {user. fullName} "/> </td>
</Tr>
</Table>
<Table width = "752" border = "1px;" align = "center" style = "border-collapse: collapse; border: 1px solid black; margin: auto; "id =" t3 ">
<Tr>
<Td width = "76" rowspan = "2"> shipment status </td>
<Td width = "80" height = "30px;"> shipping time </td>
& Lt; td width = "139" & gt;
<Input name = "sendTime" id = "sendTime" type = "text" class = "date textInput readonly" style = "width: 83%; height: 24px; "readonly =" readonly "/>
<A class = "inputDateButton" href = "javascript:;"> select </a>
</Td>
<Td width = "119"> longitude </td>
<Td width = "128"> <input name = "dealPerson" id = "dealPerson" disabled = "true" type = "text" style = "width: 95.5%; height: 24px; "value =" $ {user. fullName} "/> </td>
<Td width = "170"> internal invoice number </td>
</Tr>
<Tr>
<Td height = "30px;"> carrier </td>
<Td> <input name = "sendUnit" id = "sendUnit" type = "text" style = "width: 96%; height: 24px;"/> </td>
<Td> waybill number </td>
<Td> <input name = "postId" id = "postId" type = "text" style = "width: 95.5%; height: 24px;"/> </td>
<Td> <input name = "innerSendOrderNum" id = "innerSendOrderNum" type = "text" style = "width: 96.5%; height: 24px;"/> </td>
</Tr>
</Table>
<Table width = "752" border = "1px;" align = "center" style = "border-collapse: collapse; border: 1px solid black; margin: auto; "id =" t4 ">
<Tr>
<Td width = "219" rowspan = "4"> invoicing application </td>
<Td width = "70" height = "30px;"> full name of customer (receipt) </td>
<Td colspan = "4"> <input name = "custChecks" id = "custChecks" type = "text" style = "width: 98.5%; height: 24px; "/> </td>
</Tr>
<Tr>
<Td height = "30px;"> unit address </td>
<Td colspan = "4"> <input name = "companyAddr" id = "companyAddr" type = "text" style = "width: 98.5%; height: 24px; "/> </td>
</Tr>
<Tr>
<Td height = "30px;"> unit tax ID </td>
<Td width = "53" colspan = "2"> <input name = "cardNo" id = "cardNo" type = "text" style = "width: 95.5%; height: 24px; "/> </td>
<Td width = "76"> phone number </td>
<Td width = "152"> <input name = "phone" id = "phone" type = "text" style = "width: 96.5%; height: 24px; "/> </td>
</Tr>
<Tr>
<Td height = "30px;"> bank account </td>
<Td colspan = "2"> <input name = "acctBank" id = "acctBank" type = "text" style = "width: 95.5%; height: 24px; "/> </td>
<Td> account </td>
<Td> <input name = "acctNum" id = "acctNum" type = "text" style = "width: 96.5%; height: 24px;"/> </td>
</Tr>
<Tr>
<Td rowspan = "4"> invoice issuance and receipt </td>
<Td height = "30px;"> invoicing time </td>
<Td colspan = "2"> <input name = "invoiceTime" id = "invoiceTime" type = "text" class = "date textInput readonly" style = "width: 83%; height: 24px; "readonly =" readonly "/>
<A class = "inputDateButton" href = "javascript:;"> select </a> </td>
<Td> invoice number </td>
<Td> <input name = "invoiceNum" id = "invoiceNum" type = "text" style = "width: 96.5%; height: 24px;"/> </td>
</Tr>
<Tr>
<Td rowspan = "3"> invoice amount </td>
<Td height = "30px;" width = "55px;"> amount </td>
<Td width = "75px;"> <input name = "invoiceMoney" id = "invoiceMoney" type = "text" style = "width: 92%; height: 24px; "/> </td>
<Td> ticket recipient </td>
<Td> <input name = "invoiceTaker" id = "invoiceTaker" type = "text" style = "width: 96.5%; height: 24px;"/> </td>
</Tr>
<Tr>
<Td height = "30px;"> Tax Amount </td>
<Td> <input name = "invoiceTax" id = "invoiceTax" type = "text" style = "width: 92%; height: 24px;"/> </td>
<Td> receipt time </td>
<Td>
<Input name = "invoiceTakeTime" id = "invoiceTakeTime" type = "text" class = "date textInput readonly" style = "width: 86%; height: 24px; "readonly =" readonly "/>
<A class = "inputDateButton" href = "javascript:;"> select </a>
</Td>
</Tr>
<Tr>
<Td height = "30px;"> total price Tax </td>
<Td> </td>
<Td> carrier/Ticket No. </td>
<Td> <input name = "invoiceOddNum" id = "invoiceOddNum" type = "text" style = "width: 96.5%; height: 24px;"/> </td>
</Tr>
</Table>
<Table width = "752" border = "1px;" align = "center" style = "border-collapse: collapse; border: 1px solid black; margin: auto; "id =" t5 ">
<Tr>
<Td width = "73" height = "30px;"> remarks </td>
<Td width = "663"> <input name = "desc" id = "desc" type = "text" style = "width: 99.1%; height: 24px; "/> </td>
</Tr>
</Table> <br/>
<P style = "left: 660px; color: red"> Note: ①. Click a cell. "total fare (RMB) "Add rows </p> <br/>
<P style = "left: 292px; color: red"> ②. Click the cell "real grid total (RMB)" to delete the row. </p>
<P> </p>
<P> </p>
<P> </p>
<P> </p>
<P> </p>
<P> </p>
<P> </p>
</Div>
</Div>
<Div class = "formBar">
<Ul>
<Li> <div class = "buttonActive"> <div class = "buttonContent"> <button type = "submit"> submit </button> </div> </li>
<Li> <div class = "button"> <div class = "buttonContent"> <button type = "button" class = "close"> cancel </button> </div> </div> </li>
</Ul>
</Div>
</Form>
</Body>
</Html>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.