Solved

Get value before .onChange()

Posted on 2016-10-24
5
25 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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks!  Will give it a try.
0
 
LVL 5

Author Closing Comment

by:Isaac
Comment Utility
Thanks!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
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)

771 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

10 Experts available now in Live!

Get 1:1 Help Now