Reputation: 31
i am new laravel ...facing problem in getting value in javscript variable below code :
var id = $("#question_id").html('{{ $value->question_id }}');
Using div in blade part
<div id="question_id">{{ $value->question_id }}</div>
how to get question id in var id?Getting error value not define i use foreach loop it shows nothing? how to proceed?
Upvotes: 1
Views: 1067
Reputation: 54
Maybe you can use data attributes to pass variables
<div id="question_id" data-field-id="{{ $value->question_id }}"></div>
<script>
var id = $("#question_id").data("field-id");
</script>
It is still possible that some of this will work:
var id = $("#question_id").html("{{ $value->question_id }}");
var id = $("#question_id").html("{!! $value->question_id !!}");
var id = $("#question_id").html(<?php echo $value->question_id; ?>);
Upvotes: 1