Solved

Get value before .onChange()

Posted on 2016-10-24
5
35 Views
Last Modified: 2016-10-24
How can I get the value of a textbox before onChange?
Here's my jsfiddle. Change the value in any of the checkboxes.

http://jsfiddle.net/isogunro/sb4ohdkj/15/

Thanks for any help you can provide.
0
Comment
Question by:Isaac
  • 2
5 Comments
 
LVL 35

Assisted Solution

by:Robert Schutt
Robert Schutt earned 250 total points
ID: 41857480
You could store the old value in a data attribute on focus: http://jsfiddle.net/sb4ohdkj/16/
$('table#Prioritize').on('focus','input[type=text]',function(e){
    $(this).data('oldval', $(this).val());
});
$('table#Prioritize').on('change','input[type=text]',function(e){
    alert("New Value: "+$(this).val());
    alert("Old Value: "+$(this).data('oldval'));
});

Open in new window

Think about whether you want to keep the original or store the 'new old value' on subsequent edits.
0
 
LVL 82

Accepted Solution

by:
hielo earned 250 total points
ID: 41857483
try:
$('table#Prioritize').on('change','input[type=text]',function(e){
	if(!this.oldValue)
  	{
             this.oldValue = this.defaultValue;
         }
    alert("Old Value: "+$(this).prop('oldValue'));
    alert("New Value: "+$(this).val());
    //update the "oldValue" with the "current value" so that on the next change it will be seen as "old"
    this.oldValue=this.value;
});

Open in new window

0
 
LVL 5

Author Comment

by:Isaac
ID: 41857665
Thanks!  Will give it a try.
0
 
LVL 5

Author Closing Comment

by:Isaac
ID: 41857885
Thanks!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now