Solved

Get value before .onChange()

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

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
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 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…

839 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