Comparing two string variables

I have a form with text input and this is the function that is executed onchange event (inputObject is the input text object that this event was fired on):

Now when alert comes out it says: current=*123.00* new=*123.00* but it shows B on the next alert, why??
Both variables should be strings. originalInputValues array consist of inputObject.value's previously inserted.
It seems so obvious to be equal. Why it is not??
I've tried equals() and eval(). Please help

Could it be that there is some issue in javascript when comparing array entries with strings ??
What else could it be?

Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15385

6

posted Aug 31, 2009 10:13:46

0

There should be no problems, make sure you are not cached.

What about forcing to be strings?

if (original.toString() == newValue.toString()){

Eric

Pawel Nowacki
Ranch Hand

Joined: Nov 14, 2008
Posts: 67

posted Aug 31, 2009 10:34:40

0

I've cleaned cached, reopened browser and tried:

if (original.toString() == newValue.toString()){

with the same result...

It can't be happening for real....

This originalInputValues array is associative array, could it be the reason? Associative arrays have something like {one:value1, two:value2, three:value3, ...} representation.
But alert shows it like "value1" (probably alert is using toString() anyway) and this condition is also false when using toString() on both variables.

There's no such thing as an "associative array" in JavaScript. It's just a JavaScript object to which dynamic properties have been added. And no, values stored as object properties act the same as any other values, so that can't be an issue.

Pawel Nowacki
Ranch Hand

Joined: Nov 14, 2008
Posts: 67

posted Aug 31, 2009 11:40:23

0

I think problem can be somewhere else than in javascript. This script is embedded in jsp file working in Struts framework.
I've tried and write whole contruction in plain html/javascript and it works.

I have a form with text input and this is the function that is executed onchange event (inputObject is the input text object that this event was fired on):

Now when alert comes out it says: current=*123.00* new=*123.00* but it shows B on the next alert, why??
Both variables should be strings. originalInputValues array consist of inputObject.value's previously inserted.
It seems so obvious to be equal. Why it is not??
I've tried equals() and eval(). Please help

Problem solved. I've played events too much. I have onchange, onfocus and onblur events in one input:

That is because I want this field to be checked if it is a number. Then I want to disable submit button if all values on form come back to their original values.
To do this I must remember original value (onfocus) and then if something change compare this new value to original and see if other values are also in original state so I can
disable submit button.
onblur use this self.focus() function because if someone put a non-number value, browser shouldnt permit user to tab to another field (keep focus). SetTimeout is for Firefox browser so it
postpone focus execution.

Problem was that i've put this in each function and while processing one event there was other event that overlapped and override my key variable (after first alert).
I've changed it to pass this.value and this.name. Also, I've added break to for loop that iterates through originalInputValues whenever entry is found.

Im not happy with this design. But this is the only idea that comes to my mind right now. Maybe you have some advise on how to save original state of all form values and then
watch for it and disable/enable submit button?

Cloudgen C.F. Wong
Greenhorn

Joined: Jul 15, 2009
Posts: 19

posted Sep 01, 2009 01:44:17

0

How about disable all the remaining input box(es) once the user focus on one input box and the format of the input text is not numeric value.
Using the onkeyup event to check the format and enable all the remaining field if it is numeric value.

It may be better than the setTimeout for focus the original input box.

Sounds good to me, but if I disable remaining input box(es) Im still able to tab to save button (or anything else not disabled) and there is a requirement that it should not
pass to other control if its not number.
Still setTimeout its not good thing, I agree.
I'll check this link. Thank you Cloudgen.

I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com