473,408 Members | 2,087 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,408 software developers and data experts.

previous value

smiley22
I would like to know how to check the current value and the previous value entered by user before changes.

for example, the form will allow user to enter customer number. The first time user enter 10 then change to 22

customer number : 10 -> change to 22

how do I get the previous value which is 10 in this case


thanks...
Jun 12 '07 #1
6 2142
gits
5,390 Expert Mod 4TB
hi ...

in that case you have to store the values in your app ... it is a good idea to write a kind of utility-function for that purpose ... one that loops through your desired formelements and stores the values of each element within an content-object or something like this. it should create something like the following:

Expand|Select|Wrap|Line Numbers
  1. // content object
  2. var content_obj = {
  3.     element_name_or_id_1: value,
  4.     element_name_or_id_2: value,
  5.     element_name_or_id_3: value,
  6.     element_name_or_id_4: value
  7.     // as much elements as you need
  8. };
  9.  
later ... probably in the onchange-event of your elements you check the newvalue against the one of your content-object.

Expand|Select|Wrap|Line Numbers
  1. // refer properly to element_name_or_id_1 (here we use the id)
  2. var ele = document.getElementById('element_name_or_id_1');
  3. if (ele.value != content_obj['element_name_or_id_1']) {
  4.      // or whatever you want to check
  5. }
  6.  
you may set the content_obj[element_name_or_id_1] to newvalue when the check was successful or call your utility-function again so that it stores the actual values and you may compare again old- and newvalues ...

thats the idea ... hope it helps ...

kind regards ...
Jun 12 '07 #2
dmjpro
2,476 2GB
I would like to know how to check the current value and the previous value entered by user before changes.

for example, the form will allow user to enter customer number. The first time user enter 10 then change to 22

customer number : 10 -> change to 22

how do I get the previous value which is 10 in this case


thanks...
see onchange event fired when the an element loses focus and the value changed.
so on firing this event the updated value we can get , not the previous value.
so try this ......

Expand|Select|Wrap|Line Numbers
  1. <input type = text onfocus = fun1(this) onblur = fun2(this)>
  2.  
Expand|Select|Wrap|Line Numbers
  1. var prev_value,cur_value;
  2. function fun1(val)
  3. {
  4. prev_value = val.value;
  5. }
  6. function fun2(val)
  7. {
  8. cur_value = val.value;
  9. }
  10.  
i hop it ll help u.
best of luck

kind regards,
dmjpro.
Jun 12 '07 #3
gits
5,390 Expert Mod 4TB
see onchange event fired when the an element loses focus and the value changed.
so on firing this event the updated value we can get , not the previous value.
so try this ......

Expand|Select|Wrap|Line Numbers
  1. <input type = text onfocus = fun1(this) onblur = fun2(this)>
  2.  
Expand|Select|Wrap|Line Numbers
  1. var prev_value,cur_value;
  2. function fun1(val)
  3. {
  4. prev_value = val.value;
  5. }
  6. function fun2(val)
  7. {
  8. cur_value = val.value;
  9. }
  10.  
i hop it ll help u.
best of luck

kind regards,
dmjpro.
hi

... the focus event is a good point to store the value, your'e right, but onblur is not ... onchange is even better ... because you may change the value with pressing enter and then the field don't loose focus and nothing blurs ...

kind regards ...
Jun 12 '07 #4
dmjpro
2,476 2GB
hi

... the focus event is a good point to store the value, your'e right, but onblur is not ... onchange is even better ... because you may change the value with pressing enter and then the field don't loose focus and nothing blurs ...

kind regards ...
that means u say if the value changed without changing it's value then onchange event firing.
right???
i just need confirmation.

kind regards,
dmjpro.
Jun 12 '07 #5
gits
5,390 Expert Mod 4TB
that means u say if the value changed without changing it's value then onchange event firing.
right???
i just need confirmation.

kind regards,
dmjpro.
no ... you change the value and press enter ... then no blur-event fires but the onchange do!

kind regards ...
Jun 12 '07 #6
dmjpro
2,476 2GB
no ... you change the value and press enter ... then no blur-event fires but the onchange!

kind regards ...
oh i seee ..... thanksssssss

kind regards,
dmjpro.
Jun 12 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: george | last post by:
Can anyone help? I query a database and return a result on the column "reference". There might be 7 listings. Each row is displayed in a table, with links through to a detail page. I am working...
8
by: asd | last post by:
I need to find the value/index of the previously selected item of a select list. That is, when the user selects an item from the list and a certain condition elsewhere in the form is not met, I...
1
by: Andy Wells | last post by:
I'm using VB.NET and I have an application that binds a schema to the main form's controls, and the user has the ability to load an XML file through the schema and into the bound form. My...
1
by: Blake Versiga | last post by:
When editing a datagrid (C#) I need to know if the user changed the value of cell AND what the previous value was. Is this possible? If so how do I get the previous value or at least if the...
8
by: Jeff | last post by:
A client wants a press of the Enter key in a field on a continuous form to grab the value of that field from the previous record. But if they have typed a value and then hit Enter it shouldn't. ...
1
by: neelesh kumar | last post by:
i have 4 optionbuttons in my form. if i select 1st optionbutton traineeans.value=1,2ndbutton traineeans.value=2...like that.If he didnt select anyone traoneeans.value=0. one commandbutton is there...
1
by: roveagh1 | last post by:
Hi I've been using the 2 year old link below to repeat values from previous record field into current corresponding field. It's worked fine for text but the last piece of advice was to use the same...
3
by: md9108 | last post by:
I have a previous page and next page coded. The next page works. The previous page gives me an http: 404 error and I can't figure it out. The error is on the line "<td align=left> <!-- ...
3
by: ITAutobot25 | last post by:
Now this is really the last problem (for real now) with this assignment. My sorter is not working. I managed to sort by product name in my previous assignment; however, I can't get it to work on this...
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...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.