473,394 Members | 1,645 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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(rowNumber) {
document.getElementsById('matPerPiece' + rowNumber).value =
(document.getElementsById('matPOTotal' + rowNumber) /
document.getElementsById('QuantityMade'));
}

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

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

Greg.
Jul 20 '05 #1
1 4772
"Greg" <gr********@yahoo.com> wrote in message
news:38**************************@posting.google.c om...
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(rowNumber) {
document.getElementsById('matPerPiece' + rowNumber).value =
(document.getElementsById('matPOTotal' + rowNumber) /
document.getElementsById('QuantityMade'));
}

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

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'+rowNumber]

- 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(rowNumber){
var els = document.forms['costsheet'].elements;
els['matPerPiece'+rowNumber].value =
(els['matPOTotal'+rowNumber].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
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...
1
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...
10
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...
1
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...
3
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...
6
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 ...
5
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...
10
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...
5
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...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...

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.