While I click on select element, I need to remember old value of the selected element.
This code works in FF,CHROME and OPERA instead of IE.
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 like the problem is that the 2nd click(choosing new option) will fire before the 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 something
$('span').text($(this).data('oldValue'));
//trigger focus to set new oldValue
$(this).trigger('focus');
});
}
);
</script>
(Example also uses data suggested by prodigitalson)
I would use the data
infrastructure for this:
$('#viewTableOrders tr td > select').click(function() {
var old = {};
old.currentPath = $(this).val();
old.id = $(this).attr('title');
old.currentDate = $('#viewTableOrders tr#vagon' + old.id + '> td >input.input_ver1').val();
old.ajaxData = {};
$(this).data('oldData', old);
}).change(function() {
var oldData = $(this).data('oldData');
if(typeof old == 'object'){
// do stuff with oldData
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With