I'm using Laravel and I have two php variable in my blade view like this:
$dropDown = $formDataValue['name']
$emptyDropDown = $formDataValue['name'];
And I create a Javascript function with two parameters in same blade view:
function autoFill (dropDown, emptyDropDown) {
$("#" + dropDown ).change(function() {
$.ajax({
type: "GET",
url: "https://api.myjson.com/bins/bcnss",
success: function(response){
var dataLength = response.length;
$("#" + dropDown).empty();
$("#" + dropDown).append("<option value=''>Select</option>");
for( var i = 0; i< dataLength; i++){
var id = response[i].id;
var name = response[i].name;
$("#" + dropDown).append("<option value='"+id+"'>" + name + " </option>");
}
}
});
});
}
Then I call this:
<?php echo "<script> autoFill(".$dropDown.", ".$emptyDropDown."); </script>"; ?>
Problem is they can pass the parameters to function! I check element in browser and I see when I call this function, it's have parameters. But in the script tag, there nothing!

How I can fix this?
Thank you very much!
Seems like you forgot about quotes, when you are passing strings into function.
<script>
$(document).ready(function () {
autoFill('{{ $dropDown }}', '{{ $emptyDropDown }}');
});
</script>
You can do it this way, but you shouldn't, because Laravel Blade do it for you itself.
<?php echo "<script> autoFill('".$dropDown."', '".$emptyDropDown."'); </script>"; ?>
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