By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,846 Members | 1,211 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,846 IT Pros & Developers. It's quick & easy.

generated cell in a table using javascript function is not calculating the values

P: 23
Expand|Select|Wrap|Line Numbers
  1. function cal()
  2. {
  3.     var f = document.form1;
  4.     var regExp_Count = new RegExp("^[0-9)(-]+$");
  5.    f.price1.value = parseFloat(f.baseprice.value*(f.percen.value/100)).toFixed(0);
  6. }
cal() functions , will calculate as such in that formula n display in the price1 text
using the text property onblur,

<input id="percen" name="percen" size="6" maxlength="2" onblur="cal();" onkeyup="valid(this,'notnumbers')" type="text" />

this used to further added two input text , Problem Area ,
<a href="javascript: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.onblur='cal()'
percentage.onkeyup=valid(this,'notnumbers')

some times with onkeyup event , it shows "error on page" on the status bar .

plz Suggest ....
Expand|Select|Wrap|Line Numbers
  1. js
  2. function addRow()
  3. {
  4.   var tbl = document.getElementById('tbl');
  5.   var lastRow = tbl.rows.length;
  6.   if(lastRow <= 3) 
  7.   {
  8.       var iteration = lastRow;
  9.       var row = tbl.insertRow(lastRow);
  10.       row.align = 'center';
  11.           // Column 1
  12.       var cell2 = row.insertCell(0);
  13.       var percentage = document.createElement('input');
  14.       percentage.type = 'text';
  15.       percentage.name = 'percentage_add_'+iteration;
  16.       percentage.onblur='cal()'
  17.       percentage.onkeyup=valid(this,'notnumbers')
  18.       cell2.appendChild(percentage);
  19.       // Column 2
  20.       var cell3 = row.insertCell(2);
  21.       var price = document.createElement('input');
  22.       price.type = 'text';
  23.       price.name = 'major_add_'+iteration;
  24.       price.readonly='true'
  25.       cell3.appendChild(price);
  26.  
  27.      }
  28. }
  29.  
  30. <body>
  31. Base price<input id="Text1" name="baseprice" type="text" />
  32. <input id="percen" name="percen" size="6" maxlength="2" onblur="cal();" onkeyup="valid(this,'notnumbers')" type="text" />
  33. <input id="price1" type="text" /><a href="javascript:addRow()">Add Row</a>
  34.  <div>
  35.         <table id="tbl">
  36.         </table>
  37.         </div>
  38. </body>
  39.  
  40. function cal()
  41. {
  42.     var f = document.form1;
  43.     var regExp_Count = new RegExp("^[0-9)(-]+$");
  44.    f.price1.value = parseFloat(f.baseprice.value*(f.percen.value/100)).toFixed(0);
  45. }
  46.  
  47. function valid(o,w)
  48. {
  49.   var r={'notnumbers':/[^\d]/g}    
  50.   o.value = o.value.replace(r[w],'');
  51. }
  52.  
Feb 17 '09 #1
Share this Question
Share on Google+
4 Replies


RamananKalirajan
100+
P: 607
Hello, the main problem in ur code is that u havent created a form in ur page. Please create a form with the name and id form1... The calculation part will work...


Thanks and Regards
Ramanan Kalirajan
Feb 17 '09 #2

P: 23
I have form1 in the code ,

Expand|Select|Wrap|Line Numbers
  1. <form id="form1" runat="server">
  2. Base price<input id="Text1" name="baseprice" type="text" />
  3. <input id="percen" name="percen" size="6" maxlength="2" onblur="cal();" onkeyup="valid(this,'notnumbers')" type="text" />
  4. <input id="price1" type="text" /><a href="javascript:addRow()">Add Row</a>
  5.  <div>
  6.         <table id="tbl">
  7.         </table>
  8.         </div>
  9. </form>
Am i clear , with the issue....plz enlightn me if its confusing .
Thanks ...
Feb 17 '09 #3

P: 23
Whether generated cell
" percentage.type = 'text'; " using the addrow function , is calling cal() function ,?
Feb 17 '09 #4

acoder
Expert Mod 15k+
P: 16,027
Change those lines to:
Expand|Select|Wrap|Line Numbers
  1. percentage.onblur= cal;
  2. percentage.onkeyup= function() {valid(this,'notnumbers'); }
Feb 18 '09 #5

Post your reply

Sign in to post your reply or Sign up for a free account.