Forum Moderators: open

Message Too Old, No Replies

detect text field change

         

bubblebug

3:46 pm on Oct 27, 2005 (gmt 0)

10+ Year Member



Hi

How can I detect if a user has changed a form field without putting javascript in the form field tag?

I could normally use an onChange or keyUp on the tag but I can not do that in this case. Is there a way of detecting a change to its value without using these methods.

What I am looking for is something like this which will obviously not work because I made it up on the spot.

if ( document.forms.theForm.theField.changed == true ) {

document.write('Ive changed');

}

I am not too hot with javascript as you can probably tell but if anyone knows a way of doing this or even just a point in the right direction.

Scally_Ally

4:16 pm on Oct 27, 2005 (gmt 0)

10+ Year Member



could you not store what is in the text boxes when the page loads, then on the keyup call check each of your text boxes to see if they differ?

var textBox1 = "original value";
var textBox2 = "original value";
var textBox3 = "original value";
function is_it_different(){
if (document.theForm.theTextBox1.value!= textBox1){
document.write "ive changed";
}
//and so on for all three
}

would this work for you?

Bernard Marx

4:36 pm on Oct 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I could normally use an onChange or keyUp on the tag but I can not do that in this case

How about adding the onchange handler dynamically?

bubblebug

9:07 am on Oct 28, 2005 (gmt 0)

10+ Year Member



Thanks for your tips

I am not sure what you mean by adding the onchange dynamically.

I have decided to explore the first suggestion.

I now have the problem of dealing with arrays in javascript.

I am learning......

I cannot seem to access the values of one array that was set in a different function.

Scally_Ally

10:44 am on Oct 28, 2005 (gmt 0)

10+ Year Member



there shouldnt be a problem i dont think..

If you declare your variables and arrays outside the first function, you can then acccess them from within any function.

If you still havin problems post some code so we can have a look.

bubblebug

10:57 am on Oct 28, 2005 (gmt 0)

10+ Year Member



Hi, thanks

I have it working in Mozilla now as I want it to.

I discovered that initially declaring the array and vars outside the function works.

Now I need to make it work in IE.

I think it is how I am referencing the form elements that is not working.

Thanks again.

bubblebug

11:05 am on Oct 28, 2005 (gmt 0)

10+ Year Member



I dont think it is how I am referencing the elements of the form.

When I try to return the length ie ( theArray.length ) of an array I am getting 'undefined' instead of a number of items in the array.

bubblebug

11:56 am on Oct 28, 2005 (gmt 0)

10+ Year Member



I have found the problem IE returns undefined if the array only has one element.

Thanks again