Expand|Select|Wrap|Line Numbers
- function cal()
- {
- var f = document.form1;
- var regExp_Count = new RegExp("^[0-9)(-]+$");
- f.price1.value = parseFloat(f.baseprice.value*(f.percen.value/100)).toFixed(0);
- }
using the text property onblur,
<input id="percen" name="percen" size="6" maxlength="2" onblur="cal();" onkeyup="valid( this,'notnumber s')" type="text" />
this used to further added two input text , Problem Area ,
<a href="javascrip t:addRow()">Add Row</a>
addRow() functions which adds two input text control ,
cell1 couldnt able to calculate , and display on the cell2 .as it did on the other input text control
i Think these lines giving an issue ,
percentage.onbl ur='cal()'
percentage.onke yup=valid(this, 'notnumbers')
some times with onkeyup event , it shows "error on page" on the status bar .
plz Suggest ....
Expand|Select|Wrap|Line Numbers
- js
- function addRow()
- {
- var tbl = document.getElementById('tbl');
- var lastRow = tbl.rows.length;
- if(lastRow <= 3)
- {
- var iteration = lastRow;
- var row = tbl.insertRow(lastRow);
- row.align = 'center';
- // Column 1
- var cell2 = row.insertCell(0);
- var percentage = document.createElement('input');
- percentage.type = 'text';
- percentage.name = 'percentage_add_'+iteration;
- percentage.onblur='cal()'
- percentage.onkeyup=valid(this,'notnumbers')
- cell2.appendChild(percentage);
- // Column 2
- var cell3 = row.insertCell(2);
- var price = document.createElement('input');
- price.type = 'text';
- price.name = 'major_add_'+iteration;
- price.readonly='true'
- cell3.appendChild(price);
- }
- }
- <body>
- Base price<input id="Text1" name="baseprice" type="text" />
- <input id="percen" name="percen" size="6" maxlength="2" onblur="cal();" onkeyup="valid(this,'notnumbers')" type="text" />
- <input id="price1" type="text" /><a href="javascript:addRow()">Add Row</a>
- <div>
- <table id="tbl">
- </table>
- </div>
- </body>
- function cal()
- {
- var f = document.form1;
- var regExp_Count = new RegExp("^[0-9)(-]+$");
- f.price1.value = parseFloat(f.baseprice.value*(f.percen.value/100)).toFixed(0);
- }
- function valid(o,w)
- {
- var r={'notnumbers':/[^\d]/g}
- o.value = o.value.replace(r[w],'');
- }