I am not familiar with coffee script, I try to move jquery from view to put in asset but not able to make it work.
Here the working from view:
- jquery_ready do
$('label[for=voucher_name], input#voucher_name').hide();
$( "#voucher_voucher_provider_id" ).change(function() {
var exist_id = $(this).val();
var ids = $('#voucher_false_ids_')[0].value;
if(jQuery.inArray(exist_id, ids.split(" ")) !== -1){
$('label[for=voucher_name], input#voucher_name').hide();
}
else
{
$('label[for=voucher_name], input#voucher_name').show();
}
});
Then in /app/assets/javascript/mycode.js.coffee
jQuery ->
$('label[for=voucher_name], input#voucher_name').hide();
$( "#voucher_voucher_provider_id" ).change ->
exist_id = $(this).val();
ids = $('#voucher_false_ids_')[0].value;
alert('alert');
If(jQuery.inArray(exist_id, ids.split(" ")) !== -1)
$('label[for=voucher_name], input#voucher_name').hide();
else
$('label[for=voucher_name], input#voucher_name').show();
So far, I able to run until .change -> alert('alert'); Not after I start put all line after If
which cause error:
ExecJS::RuntimeError at /admin
SyntaxError: [stdin]:6:51: unexpected =
Help: for proper syntax or what is the error coming from /Thanks
Ifshould beifand!==should be!=. Or just leave the JavaScript as JavaScript.