Solved

Get value before .onChange()

Posted on 2016-10-24
5
44 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

813 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