javascript - jquery click (remember OLD VALUE) -
while click on select element, need remember old value of selected element.
code works in ff,chrome , opera instead of ie.
- remember old value.
- choose select option , replace old value remembered selected option!
code:
$(document).ready(function() { $('#viewtableorders tr td > select').click(function() { oldcurrentpath = $(this).val(); oldid = $(this).attr('title'); oldcurrentdate = $('#viewtableorders tr#vagon' + oldid + '> td >input.input_ver1').val(); dataajax = {}; }); /* event on change path */ $('#viewtableorders tr td > select').change(function() { //do something... + old value }); });
it looks problem 2nd click(choosing new option) fire before change-event.
try using focus instead of click:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script> <select> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> </select>old value is:<span></span> <script> $(document).ready( function() { $('select').focus(function() { //store old value $(this).data('oldvalue',$(this).val());} ); $('select').change(function() { //do $('span').text($(this).data('oldvalue')); //trigger focus set new oldvalue $(this).trigger('focus'); }); } ); </script> (example uses data suggested prodigitalson)
Comments
Post a Comment