473,395 Members | 1,720 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,395 software developers and data experts.

Using a Varibal on and object

I have multiple text fields in my page called
Con_Hours0 Old_Con_Hours0
Con_Hours1 Old_Con_Hours1
Con_Hours2 Old_Con_Hours2
Con_Hours3 Old_Con_Hours3
etc
etc

In my java script I want to loop through and pick up the values of each
field so I was looking at replacing the number with a variable
sort of like this
Count = 0

While Count < 10
if DocumentName.Con_Hours" + Count + ".value != DocumentName.Old_Con_Hours"
+ Count + ".value
{
alert("Things Have been Changed in Row Number" + Count);
}
loop

I can not get it to work, can you guys advise where I am going wrong?
Many Thanks

Mark
Jul 23 '05 #1
2 1175
sh0t2bts wrote:
I have multiple text fields in my page called
Con_Hours0 Old_Con_Hours0
Con_Hours1 Old_Con_Hours1
Con_Hours2 Old_Con_Hours2
Con_Hours3 Old_Con_Hours3
etc
etc

In my java script I want to loop through and pick up the values of each field so I was looking at replacing the number with a variable
sort of like this
Count = 0

While Count < 10
if DocumentName.Con_Hours" + Count + ".value != DocumentName.Old_Con_Hours" + Count + ".value
{
alert("Things Have been Changed in Row Number" + Count);
}
loop

I can not get it to work, can you guys advise where I am going wrong?
Many Thanks

Mark


Interesting syntax. Interesting, just not JavaScript.

var n = 0,
Con_Hours,
Old_Con_Hours,
f;
if (f = document.forms[0])
{
var els = f.elements;
while ((Con_Hours = els['Con_Hours' + n])
&& (Old_Con_Hours = els['Old_Con_Hours' + n]))
{
if (Con_Hours.value != Old_Con_Hours.value)
alert("Things Have been Changed in Row Number " + n);
++n;
}
}

Read this:

http://jibbering.com/faq/faq_notes/square_brackets.html

Jul 23 '05 #2
In article <t0***************@newsfe1-win.ntli.net>,
"sh0t2bts" <sh******@hotmail.com> wrote:

In my java script I want to loop through and pick up the values of each
field so I was looking at replacing the number with a variable
sort of like this
Count = 0

While Count < 10
if DocumentName.Con_Hours" + Count + ".value != DocumentName.Old_Con_Hours"
+ Count + ".value


I do not recognize this as valid javascript syntax.

I suggest that you invest in a Javascript book. The best book for
experienced programmers is: javascript: The Definitive Guide by David
Flanagan.

Here is a possible solution:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Saving stats</title>
<base href="http://spaceplace.jpl.nasa.gov/en/">
<script type="text/javascript">
/*
Con_Hours0 Old_Con_Hours0
Con_Hours1 Old_Con_Hours1
Con_Hours2 Old_Con_Hours2
Con_Hours3 Old_Con_Hours3
etc
etc

In my java script I want to loop through and pick up the values of each
field so I was looking at replacing the number with a variable
sort of like this

*/


// array is a good place to store a numeric list

var old_con_hours = [ ]

function validate(x)
{

// When true, we found a change so return false which means the form
will
// be submitted.
// When false, we found a change so return false which means the form
will
// not be submitted.
var proceed = true;

for (var i = 0;;i++)
{

// Check if the text field exists.
if (x.elements["Con_hours"+i])
{
if (x.elements["Con_hours"+i].value != old_con_hours[i] )
{
old_con_hours[i] = x.elements["Con_hours"+i].value;
alert("Con_hours number " + i + " has changed.");
proceed = false;
}
}
else
{
// since the text fields doesn't exist, we have reached the end
break;
}

}

return proceed;

}

</script>
</head>
<body >

<P>Sum up a bunch of text fields.</p>

<form name="myForm"
action="http://www.natAValidWebAddress.com"
method="POST"
onsubmit="return validate(document.forms['myForm']);">

<p>Count Hours:
<br><br>
0: <input type="text" name="Con_hours0" size="40">
<br>
1: <input type="text" name="Con_hours1" size="40">
<br>
2: <input type="text" name="Con_hours2" size="40"></p>
<br>
<br>
<input type="submit" value="Submit address information">
</form>
</p>
</body>
</html>
Jul 23 '05 #3

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

Similar topics

4
by: Michael Sparks | last post by:
Anyway... At Europython Guido discussed with everyone the outstanding issue with decorators and there was a clear majority in favour of having them, which was good. From where I was sitting it...
0
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft...
28
by: Daniel | last post by:
Hello =) I have an object which contains a method that should execute every x ms. I can use setInterval inside the object construct like this - self.setInterval('ObjectName.methodName()',...
11
by: Doug | last post by:
Is there any harm in passing an object into a method with the 'ref' keyword if the object is already a reference variable? If not, is there any benefit?
17
by: Danny J. Lesandrini | last post by:
The following code works with a standard MDB to navigate to a particluar record (with a DAO recordset, of course) but it's giving me problems in an ADP I'm working on. Dim rs As ADODB.Recordset...
4
by: Chris | last post by:
Hi, everything works apart from the last line :-(( rng.Value2.ToString() An exception is thrown : "Old format or invalid type library" It gets compiled though (so he recognizes the property...
14
by: pmud | last post by:
Hi, I need to use an Excel Sheet in ASP.NET application so that the users can enter (copy, paste ) large number of rows in this Excel Sheet. Also, Whatever the USER ENETRS needs to go to the...
1
by: kingster | last post by:
Hi, I have a regular dataset and all i want to do is make a pivot table display in a browser with the datasource of the pivot table to be this dataset and then the end-user will be able to do...
2
by: Ryan | last post by:
Hi, I receive an access denied error (see below) when attempting to send an email with BodyFormat=MailFormat.Html from an asp.net page. Exactly the same code works fine in a console...
6
by: =?Utf-8?B?U2FtZWVrc2hh?= | last post by:
Hi, I want to write a simple .net program to open a URL, fill in fields, and click on a button to submit it using .net 1.1 framework. Can someone help in suggesting the libraries I should use?...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
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...
0
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,...
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...

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.