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

Element OnReset Event?

Hi,

On my form, I turn the forecolor blue when an element's value changes by
comparing a custom "origVal" tag on each element. This works fine.

Then, when the user resets the form (double escape key), the onreset event
fires. I then loop through all the elements in the form and change the
forecolor back to black. This also works. However, it takes a long time to
loop through this because of the large number of elements on the page.

If possible, I want to process only the elements that have been reset, not
all of them. Is there some undocumented event or some method I can use to
revert the forecolor on only the changed items?

I already tried adding an "onreset" attribute to each element, but that
didn't fire. Also, the onchange event does not apply because it only fires
when a single element loses focus and has a changed value.

Thanks in advance,

Eric
Jul 23 '05 #1
3 1986
Eric wrote:
Hi,

On my form, I turn the forecolor blue when an element's value changes by
comparing a custom "origVal" tag on each element. This works fine.

Then, when the user resets the form (double escape key), the onreset event
fires. I then loop through all the elements in the form and change the
forecolor back to black. This also works. However, it takes a long time to
loop through this because of the large number of elements on the page.

If possible, I want to process only the elements that have been reset, not
all of them. Is there some undocumented event or some method I can use to
revert the forecolor on only the changed items?

I already tried adding an "onreset" attribute to each element, but that
didn't fire. Also, the onchange event does not apply because it only fires
when a single element loses focus and has a changed value.

Thanks in advance,

Eric


The following script assumes origVal is an Array.

for ( var i = 0 ; i < document.forms[ 0 ].elements.length ; i++ )
{
if ( document.forms[ 0 ].elements[ i ].value != origVal[ i ] )
{
document.forms[ 0 ].elements[ i ].style.color = '#000000';
}
}

Rob - Avagio IT Services
<a href="http://www.avagio.co.uk">Avagio IT Services</a>
Jul 23 '05 #2
Eric wrote:
On my form, I turn the forecolor blue when an element's value changes by
comparing a custom "origVal" tag on each element. This works fine.
"origVal" tag?

For "input" and "textarea" elements, there is a "defaultValue" property that
you should use and should compare against:

<input
value="foo"
onchange="this.style.color = (this.value != this.defaultValue? 'blue' :
'');"><!-- one line! -->

<textarea>
onchange="this.style.color = (this.value != this.defaultValue? 'blue' :
'');"></textarea><!-- one line! -->

(Or do that in an event listener of the "form" element object.)
Then, when the user resets the form (double escape key), the onreset event
fires. I then loop through all the elements in the form and change the
forecolor back to black. This also works. However, it takes a long time to
loop through this because of the large number of elements on the page.

If possible, I want to process only the elements that have been reset, not
all of them. Is there some undocumented event or some method I can use to
revert the forecolor on only the changed items?
You have set them to blue text color, why not test against that? Then
set the style.color property of that elements to "" to set the default
text color. You should do that with style.backgroundColor as well, and
be sure to set both text *and* background color on change of an element.

<http://www.w3.org/QA/Tips/color>
I already tried adding an "onreset" attribute to each element, but that
didn't fire.


There is no "onreset" attribute for elements other than "form" elements.

<http://www.w3.org/TR/html4/index/attributes.html
PointedEars
Jul 23 '05 #3
Thank you both for your responses...very helpful. I'm still learning as I go. :-)

Take care,

Eric
Jul 23 '05 #4

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

Similar topics

4
by: Csaba2000 | last post by:
I want to be able to programatically click on the center of an <INPUT type=image ...> element (I only care about IE 5.5+). This should work regardless of whether IE has focus. Normally you would...
1
by: Covad | last post by:
Hi all, For some reason my change() function is only called when the page loads. I'd much rather it gets called when the select changes. Here's the code: window.onload = init; function...
4
by: Eric | last post by:
How can I dynamically assign an event to an element? I have tried : (myelement is a text input) document.getElementById('myelement').onKeyUp = "myfnc(param1,param2,param3)"; ...
7
by: Peter Adolphs | last post by:
Hi newsgroup! The W3C HTML 4.01 recommendation states that "The onreset event occurs when a form is reset." Using Mozilla 1.4.1, how come that if I set onreset="return false;", the form is not...
1
by: Weston C | last post by:
Here's something I'm working on: for a click on a given element, I want to be able capture the x/y coordinates of the mouse -- that is, the mouse coordinates relative to the top left corner of said...
2
by: RobG | last post by:
I am trying to dynamically add an onclick to an element, however I just can't get the syntax right. consider the following function: function doClick (evt,x) { // do things with evt and x } ...
4
by: sjkothenbeutel | last post by:
I've been reading through quite a bit regarding this topic but am finding myself confused. Here is the scenario: I have a javascript class defined with methods whereas each has references to...
3
by: Harshpandya | last post by:
<form action="?= $postUri ?>" method="post" onSubmit="return verifyInput();" onReset="setTimeout('toggleDHCP()',100) setFormDisabled(true);"> In this code - i want to pass multiple functions...
6
by: bgold12 | last post by:
Hey, I just want to make sure that when I remove an element I don't have to worry about the events listeners I added previously to the element. For example: // get the element by its id elem =...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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:
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...
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...
0
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...

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.