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

Using a Varibal on and object

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.