473,651 Members | 2,716 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

trouble using correct syntax for getelementbyId( )

I have the following code (a one line function)

I'm trying to calculate a value for text field matPerPiece# where #
is a row number I provide. The value is calculated from text fields
matPOTotal# and QuantityMade.

The elements exist in a form named costsheet

function mattotalrow(row Number) {
document.getEle mentsById('matP erPiece' + rowNumber).valu e =
(document.getEl ementsById('mat POTotal' + rowNumber) /
document.getEle mentsById('Quan tityMade'));
}

I'm not sure how to access the values in the object that is returned
by the following syntax:
var newObj = document.getEle mentsById('fiel dname');

Thanks for your help I appreciate any suggestions you can provide.

Greg.
Jul 20 '05 #1
1 4790
"Greg" <gr********@yah oo.com> wrote in message
news:38******** *************** ***@posting.goo gle.com...
I have the following code (a one line function) I'm trying to calculate a value for text field matPerPiece#
where # is a row number I provide. The value is calculated
from text fields matPOTotal# and QuantityMade.

The elements exist in a form named costsheet

function mattotalrow(row Number) {
document.getEle mentsById('matP erPiece' + rowNumber).valu e =
(document.getE lementsById('ma tPOTotal' + rowNumber) /
document.getEl ementsById('Qua ntityMade'));
}

I'm not sure how to access the values in the object that
is returned by the following syntax:
var newObj = document.getEle mentsById('fiel dname');

Thanks for your help I appreciate any suggestions you can provide.


Given a form named 'costsheet' and an element who's name is an integer
concatenated to the end of 'matPerPiece', the code W3C HTML DOM Level 2
standard (and very back-compatible) property accessor:-

document.forms['costsheet'].elements['matPerPiece'+r owNumber]

- would be the best way of construction a global reference to a from
element.

Properties of that element would normally be accessed with dot notation,
adding, say - .value - to the end of the above reference to access the
"value" property of the element.

It is however more efficient to cache references to objects that
represent stages in repeated property accessors, such as a reference to
the form or the form's elements collection. I assume that the function
above is intended to read the value in the second two elements and
assign the result of the calculation to the value property of the first,
so something like:-

function mattotalrow(row Number){
var els = document.forms['costsheet'].elements;
els['matPerPiece'+r owNumber].value =
(els['matPOTotal'+ro wNumber].value /

els['QuantityMade'+ rowNumber].value);
}

Richard.
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1314
by: BrassWorld | last post by:
Hello! I have two tables. Each displays a make believe Bible verse in the King James Version. Using a select list (there is one for each verse) the user can choose to display either verse in the New American Standard version instead. The comments between the <!-- --> (just above the tables) explain the specific problem I'm having. Any help is appreciated. var Verse1KingJames = new String( "Thy will be done. (KJV)" ); var...
1
1942
by: Steven Spear | last post by:
Hi. I am trying to perform backtracking with this search function. Something is going wrong when I enter 2 at the command line. Entering 1 at the command line seems to work fine. I notice that backtracking never takes place. Obviously there is something wrong with my logic. I have been trying many things for many days to correct the situation, but nothing seems to help. Does anyone have any suggestions? Thanks, Steve #include...
10
2674
by: JJA | last post by:
I'm trying to use document.getElementByID inside a function where the ID is passed as an argument. I get the same error ("Element has no properties") on the same statement inside the commonCheck function with either MS IE 6.0 or Mozilla Firefox 0.9. Comments below indicate that if I hardcode an element ID I can avoid the error, but I obviously want to parameterize it. Here are some snippets of my code: -----snippet...
1
1784
by: lkrubner | last post by:
In the first version of this function, I only test for true or false, on a global var, without limiting that true or false to the id of a particular item. What this meant was that if you were using this function for several items on a page, sometimes you had to click twice and other times you only had to click once, because sometimes visibility was false though you were clicking on an item that was true. So then I started adding the id's...
3
7160
by: weston | last post by:
I'm making a foray into trying to create custom vertical scrollbars and sliders, and thought I had a basic idea how to do it, but seem to be having some trouble with the implementation. My thinking was: (a) create a div for the slider / scroll nub to move within (b) attach event handlers which, onmousedown, specify the slider/nub is moveable, and onmouseup, specify it's not (c) attach an event handler to the contaning div which,...
6
1470
by: Ted | last post by:
Here is one such function: CREATE FUNCTION my_max_market_date () RETURNS datetime BEGIN DECLARE @mmmd AS datetime; SELECT max(h_market_date) INTO @mmmd FROM holdings_tmp; RETURN @mmmd; END One change I had to make, relative to what I had working in MySQL, was
5
13974
by: JohnDriver | last post by:
Hi, I am having a form which has a text box and 3 radio buttons. I am using GET method in Ajax to pass the value. I can pass the value of the textbox fine but how to pass the value of radio button? I searched a few things on Google but I find the javascript below most useful in my case but there is some problem that my code is not running: var test = document.getElementsByName("meal"); for (i = 0; i < test.length; i++) {
10
2199
by: onetruelove | last post by:
I want to creat a post like this blog: http://onlinetoefltest.blogspot.com/2007/08/level-c-lesson-1.html When you chose all the answers and click show answer a msg box will appear and tells how many answers are correct I view the blog source and copied all the code to my post but it didn't work when i click the show answer button in my post. Can any one help me with the code? Thanks in advance
5
13348
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL http://mghospedagem.com/images/controlpanel.jpg instead of http://mghospedagem.comhttp://mghospedagem.com/images/controlpanel.jpg As u see, there's the website URL before the image URL.
0
8352
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8275
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
8802
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8465
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
8579
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...
1
6158
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5612
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();...
1
1909
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1587
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.