Reputation: 145
Here is example http://jsfiddle.net/rigaconnect/gLCjy/14/
One javascript ensures copy-paste value from above input field. User presses and holds ctrl, then click on field below.
$(document).ready(function(){
$("input").on('click', function(e) {
var name1 = $(this).closest('tr').prev().find('td:eq('+$(this).closest('td').index()+')').find('input').val();
if(e.ctrlKey) $(this).val(name1);
});
});
Second javascript changes input field value to 1 if in certain input fields value is entered or changed
<input type="text" name="is_row_changed[]" id="is_row_changed1" size="1">
<script>
$(".row_changed1").on("change", function () {
document.getElementById('is_row_changed1').value = 1;
});
</script>
html input fields are like this
<input type="text" name="date_year[]" id="date_year1" class="row_changed1" value="" size="2">
If I enter (or copy-paste) values without ctrl+click then all works as necessary.
However if I hold ctrl and click in field then value is copied and appears in the field, but value here <input type="text" name="is_row_changed[]" id="is_row_changed1" size="1">
does not change.
Enter something in left top field. Right top field value changes to 1. That is ok.
Then press and hold ctrl and click in left bottom field. Left bottom field value becomes the same as left top field's value. This is also ok.
But right bottom field value does not change. This is the problem... Actually no idea. Need advice to which direction to go....
Upvotes: 0
Views: 76
Reputation: 123739
That is because change event doesnot get triggered on programatically assined values. You can manually trigger it when you assign the value to the textbox.
$(document).ready(function () {
$("input").on('click', function (e) {
var name1 = $(this).closest('tr').prev().find('td:eq(' + $(this).closest('td').index() + ')').find('input').val();
if (e.ctrlKey) {
$(this).val(name1).trigger('change'); //Trigger the change event here.
};
});
});
Upvotes: 2