473,779 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

23 New Member
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,'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
  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
4 3118
RamananKalirajan
608 Contributor
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
sureshl
23 New Member
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
sureshl
23 New Member
Whether generated cell
" percentage.type = 'text'; " using the addrow function , is calling cal() function ,?
Feb 17 '09 #4
acoder
16,027 Recognized Expert Moderator MVP
Change those lines to:
Expand|Select|Wrap|Line Numbers
  1. percentage.onblur= cal;
  2. percentage.onkeyup= function() {valid(this,'notnumbers'); }
Feb 18 '09 #5

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

Similar topics

10
7795
by: Richard A. DeVenezia | last post by:
At line this.timerId = setInterval (function(){this.step()}, 100) I get error dialog Error:Object doesn't support this property or method. If I change it to this.timerId = setInterval (function(){this==window}, 100) I see true, the sad fact that 'this' is window and not an anim. What are some proper ways ? I would like to avoid
25
5198
by: kie | last post by:
hello, i have a table that creates and deletes rows dynamically using createElement, appendChild, removeChild. when i have added the required amount of rows and input my data, i would like to calculate the totals in each row. when i try however, i receive the error: "Error: 'elements' is null or not an object"
3
2330
by: rufus | last post by:
I am created a table dynamically and I have wrapped it in a div tag so that the user can scroll the table horizontally ie I have added an overflow property to the div. I dont want the user to be able to scroll vertically so I need to set the height of the div at runtime based on the number of table rows generated. Ideally I want the div scrollbars to sit just underneath the bottom of the table. I have looked around and haven't found...
8
17923
by: Ben | last post by:
Hi all, Just wondering how to write (using document.write) to a table cell. I have table with 3 rows and 3 colums. I want to write from within the Javascript to say third column of a first row. How do I do it? I think one way is to write the entire table out in document.write("<table>...) but I'd like to know if it is possible to access a particular cell in a table.
5
3901
by: Greg N. | last post by:
Hi folks, I have a table cell with a background image, something like <td background=landscape.jpg height=200></td> The sole purpose of this code is to display the image inside that table cell. It displays just as much of the image as the current cell width allows. The actual cell width is determined by other cells in the same table column and by the current browser window width.
3
4766
by: Peter Williams | last post by:
Hi All, I want to write some javascript for a html page which does the following. Imagine that the page contains a table with 2 columns and 3 rows, e.g.: +---+---+ | A | B | +---+---+
5
1713
by: mk | last post by:
Greetings all - im new to this newsgroup so pls dont flame me :p I need some help! Please view the html below in a browser. Or goto this url -http://firebrain.co.uk/java-problem.htm (Assuming you have seen the rendered code) Basically I need the X buttons to change all the values of each textbox to zero either in the col or row depending on which button is clicked. Function summery: If you click on a X button on the right hand side of...
1
4022
by: swetha123 | last post by:
hello , I need to alert the value entered in the text box,which is in TD cell, using DOM can any one tell how please here is the code with out a text box which is working <html> <head> <script type="text/javascript"> function cell() { var x=document.getElementById('myTable').rows.cells; alert(x.innerHTML);
0
9471
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10136
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10071
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9925
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8958
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6723
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5501
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3631
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.