I have some simple jquery calculations on form fields that i can’t get to work.
I can see the JS asset is loaded when i view page source, i have the AppAsset::register in the main layout file, yet something simple as
$('#sale-price').on('change', function() {
if ($('#percentage').val() != ""){
console.log('calculate something');
}
else {
console.log('Enter percentage first');
}
})
does not seem to work.
Now, the page im trying to use it on is being loaded as a modal - it is the standard _form.php but i’m loading it using
Modal::begin([
'header' => '<h4>New Sale</h4>',
'id' => 'modalCreateSale',
'size' => 'modal-lg',
]);
echo "<div id='modalContent'></div>";
Modal::end();
Does that change things ?
I’m using the #sale-price, based on what i can see when i inspect the element in chrome.
What is bizarre is that as a test, i added simple page load alert to the top of the file:
$(document).ready( function () {
alert("Hello, world")
});
and it only works AFTER i reload the page.
Any ideas ?