[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Get value before .onChange()

Posted on 2016-10-24
5
Medium Priority
?
82 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
4 Comments
 
LVL 35

Assisted Solution

by:Robert Schutt
Robert Schutt earned 1000 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 1000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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 If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
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…
Suggested Courses
Course of the Month19 days, 7 hours left to enroll

872 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