| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|---|
| 2 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
|---|
| 3 | <head> |
|---|
| 4 | <title>selectory-test-case</title> |
|---|
| 5 | <meta http-equiv="X-UA-Compatible" content="IE=IE7" /> |
|---|
| 6 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
|---|
| 7 | <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> |
|---|
| 8 | <script language="JavaScript" type="text/javascript"> |
|---|
| 9 | var $j = jQuery.noConflict(); |
|---|
| 10 | var template = 'path/to/template/'; |
|---|
| 11 | $j(document).ready(function(){ |
|---|
| 12 | $j('#addProduct').click(function() { |
|---|
| 13 | $j('input[name*=\\[txtProductQuantity\\]]').each(function() { |
|---|
| 14 | $j('input[name*=\\[txtProductQuantity\\]]').bind('blur', function() { |
|---|
| 15 | if ($j(this).val()) { |
|---|
| 16 | var x = $j(this).attr('name').replace('[txtProductQuantity]','\\\\[txtProductPrice\\\\]'); |
|---|
| 17 | var x = x.replace('[','\\\\['); |
|---|
| 18 | var x = x.replace(']','\\\\]'); |
|---|
| 19 | $j('#msg').html(x+' => '+$j('input[name*='+x+']').attr('name')); |
|---|
| 20 | //addTotal($j(this).val(), $j('input[name^='+x+']').val()); |
|---|
| 21 | } |
|---|
| 22 | }); |
|---|
| 23 | $j('input[name*=\\[txtProductPrice\\]]').bind('blur', function() { |
|---|
| 24 | if ($j(this).val()) { |
|---|
| 25 | var y = $j(this).attr('id').replace('[txtProductPrice]','\\\\[txtProductQuantity\\\\]'); |
|---|
| 26 | var y = y.replace('[','\\\\['); |
|---|
| 27 | var y = y.replace(']','\\\\]'); |
|---|
| 28 | $j('#msg').html(y+' => '+$j('input[name^='+y+']').val()); |
|---|
| 29 | //addTotal($j(this).val(), $j('#'+y).val()); |
|---|
| 30 | } |
|---|
| 31 | }); |
|---|
| 32 | }); |
|---|
| 33 | }); |
|---|
| 34 | }); |
|---|
| 35 | function addTotal(item, amt) |
|---|
| 36 | { |
|---|
| 37 | if (amt) { |
|---|
| 38 | var total = ($j('#txtProductTotal').val()) ? parseFloat($j('#txtProductTotal').val()) + (parseFloat(item) * parseFloat(amt)) : parseFloat(item) * parseFloat(amt); |
|---|
| 39 | } else { |
|---|
| 40 | var total = ($j('#txtProductTotal').val()) ? parseFloat($j('#txtProductTotal').val()) + (parseFloat(item) * parseFloat(amt)) : parseFloat(item); |
|---|
| 41 | } |
|---|
| 42 | $j('#txtProductTotal').val(parseFloat(total).toFixed(2)); |
|---|
| 43 | } |
|---|
| 44 | function subTotal(item, amt) |
|---|
| 45 | { |
|---|
| 46 | if (amt) { |
|---|
| 47 | var total = ($j('#txtProductTotal').val()) ? parseFloat($j('#txtProductTotal').val()) - (parseFloat(item) * parseFloat(amt)) : parseFloat(item) * parseFloat(amt); |
|---|
| 48 | } else { |
|---|
| 49 | var total = ($j('#txtProductTotal').val()) ? parseFloat($j('#txtProductTotal').val()) - parseFloat(item) : parseFloat(item); |
|---|
| 50 | } |
|---|
| 51 | $j('#txtProductTotal').val(parseFloat(total).toFixed(2)); |
|---|
| 52 | } |
|---|
| 53 | function addEmptyRow(id,count,template) |
|---|
| 54 | { |
|---|
| 55 | var formRemove = '<a href="#" alt="Remove product?" title="Remove product?">Remove row?</a>'; |
|---|
| 56 | var formQuantity = document.createElement('input'); |
|---|
| 57 | formQuantity.setAttribute('type', 'text'); |
|---|
| 58 | formQuantity.setAttribute('name', 'txtProduct['+count+'][txtProductQuantity]'); |
|---|
| 59 | formQuantity.setAttribute('id', 'txtProduct['+count+'][txtProductQuantity]'); |
|---|
| 60 | formQuantity.setAttribute('title', 'Product name for row #'+count); |
|---|
| 61 | formQuantity.setAttribute('size', '15'); |
|---|
| 62 | var formDescription = document.createElement('input'); |
|---|
| 63 | formDescription.setAttribute('type', 'text'); |
|---|
| 64 | formDescription.setAttribute('name', 'txtProduct['+count+'][txtProductDescription]'); |
|---|
| 65 | formDescription.setAttribute('id', 'txtProduct['+count+'][txtProductDescription]'); |
|---|
| 66 | formDescription.setAttribute('title', 'Product description for row #'+count); |
|---|
| 67 | var formPrice = document.createElement('input'); |
|---|
| 68 | formPrice.setAttribute('type', 'text'); |
|---|
| 69 | formPrice.setAttribute('name', 'txtProduct['+count+'][txtProductPrice]'); |
|---|
| 70 | formPrice.setAttribute('id', 'txtProduct['+count+'][txtProductPrice]'); |
|---|
| 71 | formPrice.setAttribute('title', 'Product price for row #'+count); |
|---|
| 72 | formPrice.setAttribute('size', '15'); |
|---|
| 73 | var formNumber = document.createElement('input'); |
|---|
| 74 | formNumber.setAttribute('type', 'text'); |
|---|
| 75 | formNumber.setAttribute('name', 'txtProduct['+count+'][txtProductNumber]'); |
|---|
| 76 | formNumber.setAttribute('id', 'txtProduct['+count+'][txtProductNumber]'); |
|---|
| 77 | formNumber.setAttribute('title', 'Product number for row #'+count); |
|---|
| 78 | formNumber.setAttribute('size', '15'); |
|---|
| 79 | var formSource = document.createElement('input'); |
|---|
| 80 | formSource.setAttribute('type', 'text'); |
|---|
| 81 | formSource.setAttribute('name', 'txtProduct['+count+'][txtProductSource]'); |
|---|
| 82 | formSource.setAttribute('id', 'txtProduct['+count+'][txtProductSource]'); |
|---|
| 83 | formSource.setAttribute('title', 'Product source for row #'+count); |
|---|
| 84 | formSource.setAttribute('size', '15'); |
|---|
| 85 | |
|---|
| 86 | var formFiller = '*'; |
|---|
| 87 | |
|---|
| 88 | var table = document.getElementById(id); |
|---|
| 89 | |
|---|
| 90 | if(count<0){count = table.rows.length;count++;} |
|---|
| 91 | |
|---|
| 92 | var row = table.insertRow(count); |
|---|
| 93 | |
|---|
| 94 | try { |
|---|
| 95 | var cellRemove = row.insertCell(0); |
|---|
| 96 | cellRemove.innerHTML = formRemove; |
|---|
| 97 | var cellQuantity = row.insertCell(1); |
|---|
| 98 | cellQuantity.appendChild(formQuantity); |
|---|
| 99 | var cellDescription = row.insertCell(2); |
|---|
| 100 | cellDescription.appendChild(formDescription); |
|---|
| 101 | var cellPrice = row.insertCell(3); |
|---|
| 102 | cellPrice.appendChild(formPrice); |
|---|
| 103 | var cellNumber = row.insertCell(4); |
|---|
| 104 | cellNumber.appendChild(formNumber); |
|---|
| 105 | var cellSource = row.insertCell(5); |
|---|
| 106 | cellSource.appendChild(formSource); |
|---|
| 107 | var cellFiller = row.insertCell(6); |
|---|
| 108 | cellFiller.innerHTML = formFiller; |
|---|
| 109 | |
|---|
| 110 | } catch (ex) { |
|---|
| 111 | alert(ex); |
|---|
| 112 | } |
|---|
| 113 | } |
|---|
| 114 | </script> |
|---|
| 115 | </head> |
|---|
| 116 | <body> |
|---|
| 117 | <form action="selector-test-case.html" method="post" class="auth-form" name="puchase" id="purchase"> |
|---|
| 118 | <div> |
|---|
| 119 | <div id="msg"></div> |
|---|
| 120 | <table border="0" width="100%" class="auth-form txt" cellspacing="5"> |
|---|
| 121 | <tr align="center"> |
|---|
| 122 | <td title="Add new product element?" width="20" align="left"><a href="#" title="Add new product row?" onclick="javascript:addEmptyRow('products',document.getElementById('products').rows.length,template)" id="addProduct">Add row?</td> |
|---|
| 123 | <td title="Product quantity" width="200" nowrap><strong>Quantity</strong></td> |
|---|
| 124 | <td title="Item description" width="200" nowrap><strong>Item description</strong></td> |
|---|
| 125 | <td title="Item price" width="200" nowrap><strong>Price</strong></td> |
|---|
| 126 | <td title="Part number" width="200" nowrap><strong>Part number</strong></td> |
|---|
| 127 | <td title="Part source" width="200" nowrap><strong>Part source</strong></td> |
|---|
| 128 | <td class="copyright"></td> |
|---|
| 129 | </tr> |
|---|
| 130 | <tr> |
|---|
| 131 | <td colspan="7"> |
|---|
| 132 | <table border="0" width="100%" class="auth-form txt" id="products" style="products"></table> |
|---|
| 133 | </td> |
|---|
| 134 | </tr> |
|---|
| 135 | <tr> |
|---|
| 136 | <td colspan="4"></td> |
|---|
| 137 | <td title="Total of parts list" width="2%" class="txt" align="right"><strong>Total:</strong></td> |
|---|
| 138 | <td title="Total of parts list" class="txt">$<input type="text" id="txtProductTotal" name="txtProductTotal" value="" /></td> |
|---|
| 139 | <td class="copyright" id="txtProductTotalErr" width="25" nowrap></td> |
|---|
| 140 | </tr> |
|---|
| 141 | </table> |
|---|
| 142 | </div> |
|---|
| 143 | </form> |
|---|
| 144 | </body> |
|---|
| 145 | </html> |
|---|