Problem displaying dynamic data in an array in Laravel blade view using Javascript
Working on a Laravel application whereby I have some data in an array. The data is a collection of associative arrays whereby each array has an identity number and a collection of policy codes in it. Am fetching the data and displaying to the blade. In the view I have partitioned in 2 columns (using bootstrap grid system). On the left column (col-md-4) am looping through the variable and displaying the identity number which works fine. On the right column I have a table whereby am supposed to display the respective policy code depending on the state of identity_no.
I want to achieve a functionality whereby when the user clicks or hovers over a particular identity number, the respective policy codes should be displayed on the right column (col-md-8)in the table tbody tag. The same should be repeated for subsequent identity numbers (should only display after the identity number has been clicked or hovered on).
Array collection that is stored in a variable called asm
array:1 [▼
0 => array:2 [▼
"identity_no" => "71360"
"policy_code" => array:2 [▼
0 => "IL2***********"
1 => "IL2***********"
2 => "IL2***********"
]
]
1 => array:2 [▼
"identity_no" => "68181"
"policy_code" => array:3 [▼
0 => "IL2**********"
1 => "IL2***********"
2 => "IL2***********"
3 => "IL2***********"
]
]
2 => array:2 [▼
"identity_no" => "53983"
"policy_code" => array:4 [▼
0 => "IL2*************"
1 => "IL2*************"
2 => "IL2*************"
3 => "IL2*************"
4 => "IL2*************"
5 => "IL2*************"
]
]
]
Layout on the view
<div class="row">
<!-- lEFT column -->
<div class="col-md-4">
<div id="MainMenu">
<div class="list-group panel">
<!-- Level 1 -->
@foreach($asm as $a)
<a href="#" class="list-group-item list-group-item-primary" > Identity No: {{ $a['identity_no'] }} </a>
@endforeach
<!-- END level 1-->
</div>
</div>
</div>
<!-- END left column-->
<!-- Right column-->
<div class="col-md-8">
<table id="summary-table">
<thead>
<tr>
<th>Policy Codes</th>
</tr>
</thead>
<tbody>
<tr>
<td> <!-- Add dynamic policy codes--></td>
</tr>
</tbody>
</table>
</div>
javascript laravel twitter-bootstrap associative-array laravel-blade
add a comment |
Working on a Laravel application whereby I have some data in an array. The data is a collection of associative arrays whereby each array has an identity number and a collection of policy codes in it. Am fetching the data and displaying to the blade. In the view I have partitioned in 2 columns (using bootstrap grid system). On the left column (col-md-4) am looping through the variable and displaying the identity number which works fine. On the right column I have a table whereby am supposed to display the respective policy code depending on the state of identity_no.
I want to achieve a functionality whereby when the user clicks or hovers over a particular identity number, the respective policy codes should be displayed on the right column (col-md-8)in the table tbody tag. The same should be repeated for subsequent identity numbers (should only display after the identity number has been clicked or hovered on).
Array collection that is stored in a variable called asm
array:1 [▼
0 => array:2 [▼
"identity_no" => "71360"
"policy_code" => array:2 [▼
0 => "IL2***********"
1 => "IL2***********"
2 => "IL2***********"
]
]
1 => array:2 [▼
"identity_no" => "68181"
"policy_code" => array:3 [▼
0 => "IL2**********"
1 => "IL2***********"
2 => "IL2***********"
3 => "IL2***********"
]
]
2 => array:2 [▼
"identity_no" => "53983"
"policy_code" => array:4 [▼
0 => "IL2*************"
1 => "IL2*************"
2 => "IL2*************"
3 => "IL2*************"
4 => "IL2*************"
5 => "IL2*************"
]
]
]
Layout on the view
<div class="row">
<!-- lEFT column -->
<div class="col-md-4">
<div id="MainMenu">
<div class="list-group panel">
<!-- Level 1 -->
@foreach($asm as $a)
<a href="#" class="list-group-item list-group-item-primary" > Identity No: {{ $a['identity_no'] }} </a>
@endforeach
<!-- END level 1-->
</div>
</div>
</div>
<!-- END left column-->
<!-- Right column-->
<div class="col-md-8">
<table id="summary-table">
<thead>
<tr>
<th>Policy Codes</th>
</tr>
</thead>
<tbody>
<tr>
<td> <!-- Add dynamic policy codes--></td>
</tr>
</tbody>
</table>
</div>
javascript laravel twitter-bootstrap associative-array laravel-blade
So what is the issue you are facing while achieving this?
– Mayank Pandeyz
Jan 3 at 6:56
@MayankPandeyz Am not sure how to display the policy codes in the table after a particular identity number is clicked or hovered on using Javascript
– Martin
Jan 3 at 6:59
@MayankPandeyz What`s your suggestion about it..
– Martin
Jan 3 at 7:13
add a comment |
Working on a Laravel application whereby I have some data in an array. The data is a collection of associative arrays whereby each array has an identity number and a collection of policy codes in it. Am fetching the data and displaying to the blade. In the view I have partitioned in 2 columns (using bootstrap grid system). On the left column (col-md-4) am looping through the variable and displaying the identity number which works fine. On the right column I have a table whereby am supposed to display the respective policy code depending on the state of identity_no.
I want to achieve a functionality whereby when the user clicks or hovers over a particular identity number, the respective policy codes should be displayed on the right column (col-md-8)in the table tbody tag. The same should be repeated for subsequent identity numbers (should only display after the identity number has been clicked or hovered on).
Array collection that is stored in a variable called asm
array:1 [▼
0 => array:2 [▼
"identity_no" => "71360"
"policy_code" => array:2 [▼
0 => "IL2***********"
1 => "IL2***********"
2 => "IL2***********"
]
]
1 => array:2 [▼
"identity_no" => "68181"
"policy_code" => array:3 [▼
0 => "IL2**********"
1 => "IL2***********"
2 => "IL2***********"
3 => "IL2***********"
]
]
2 => array:2 [▼
"identity_no" => "53983"
"policy_code" => array:4 [▼
0 => "IL2*************"
1 => "IL2*************"
2 => "IL2*************"
3 => "IL2*************"
4 => "IL2*************"
5 => "IL2*************"
]
]
]
Layout on the view
<div class="row">
<!-- lEFT column -->
<div class="col-md-4">
<div id="MainMenu">
<div class="list-group panel">
<!-- Level 1 -->
@foreach($asm as $a)
<a href="#" class="list-group-item list-group-item-primary" > Identity No: {{ $a['identity_no'] }} </a>
@endforeach
<!-- END level 1-->
</div>
</div>
</div>
<!-- END left column-->
<!-- Right column-->
<div class="col-md-8">
<table id="summary-table">
<thead>
<tr>
<th>Policy Codes</th>
</tr>
</thead>
<tbody>
<tr>
<td> <!-- Add dynamic policy codes--></td>
</tr>
</tbody>
</table>
</div>
javascript laravel twitter-bootstrap associative-array laravel-blade
Working on a Laravel application whereby I have some data in an array. The data is a collection of associative arrays whereby each array has an identity number and a collection of policy codes in it. Am fetching the data and displaying to the blade. In the view I have partitioned in 2 columns (using bootstrap grid system). On the left column (col-md-4) am looping through the variable and displaying the identity number which works fine. On the right column I have a table whereby am supposed to display the respective policy code depending on the state of identity_no.
I want to achieve a functionality whereby when the user clicks or hovers over a particular identity number, the respective policy codes should be displayed on the right column (col-md-8)in the table tbody tag. The same should be repeated for subsequent identity numbers (should only display after the identity number has been clicked or hovered on).
Array collection that is stored in a variable called asm
array:1 [▼
0 => array:2 [▼
"identity_no" => "71360"
"policy_code" => array:2 [▼
0 => "IL2***********"
1 => "IL2***********"
2 => "IL2***********"
]
]
1 => array:2 [▼
"identity_no" => "68181"
"policy_code" => array:3 [▼
0 => "IL2**********"
1 => "IL2***********"
2 => "IL2***********"
3 => "IL2***********"
]
]
2 => array:2 [▼
"identity_no" => "53983"
"policy_code" => array:4 [▼
0 => "IL2*************"
1 => "IL2*************"
2 => "IL2*************"
3 => "IL2*************"
4 => "IL2*************"
5 => "IL2*************"
]
]
]
Layout on the view
<div class="row">
<!-- lEFT column -->
<div class="col-md-4">
<div id="MainMenu">
<div class="list-group panel">
<!-- Level 1 -->
@foreach($asm as $a)
<a href="#" class="list-group-item list-group-item-primary" > Identity No: {{ $a['identity_no'] }} </a>
@endforeach
<!-- END level 1-->
</div>
</div>
</div>
<!-- END left column-->
<!-- Right column-->
<div class="col-md-8">
<table id="summary-table">
<thead>
<tr>
<th>Policy Codes</th>
</tr>
</thead>
<tbody>
<tr>
<td> <!-- Add dynamic policy codes--></td>
</tr>
</tbody>
</table>
</div>
javascript laravel twitter-bootstrap associative-array laravel-blade
javascript laravel twitter-bootstrap associative-array laravel-blade
asked Jan 3 at 6:50
MartinMartin
180111
180111
So what is the issue you are facing while achieving this?
– Mayank Pandeyz
Jan 3 at 6:56
@MayankPandeyz Am not sure how to display the policy codes in the table after a particular identity number is clicked or hovered on using Javascript
– Martin
Jan 3 at 6:59
@MayankPandeyz What`s your suggestion about it..
– Martin
Jan 3 at 7:13
add a comment |
So what is the issue you are facing while achieving this?
– Mayank Pandeyz
Jan 3 at 6:56
@MayankPandeyz Am not sure how to display the policy codes in the table after a particular identity number is clicked or hovered on using Javascript
– Martin
Jan 3 at 6:59
@MayankPandeyz What`s your suggestion about it..
– Martin
Jan 3 at 7:13
So what is the issue you are facing while achieving this?
– Mayank Pandeyz
Jan 3 at 6:56
So what is the issue you are facing while achieving this?
– Mayank Pandeyz
Jan 3 at 6:56
@MayankPandeyz Am not sure how to display the policy codes in the table after a particular identity number is clicked or hovered on using Javascript
– Martin
Jan 3 at 6:59
@MayankPandeyz Am not sure how to display the policy codes in the table after a particular identity number is clicked or hovered on using Javascript
– Martin
Jan 3 at 6:59
@MayankPandeyz What`s your suggestion about it..
– Martin
Jan 3 at 7:13
@MayankPandeyz What`s your suggestion about it..
– Martin
Jan 3 at 7:13
add a comment |
2 Answers
2
active
oldest
votes
You can do like this(tested on my local and found it working):
<script>
var data;
$( document ).ready(function() {
data = {!! json_encode($asm) !!};
});
$(document).on("mouseenter", "a", function() {
var policyCodes = '';
var identityNo = $(this).attr('id');
for(var i = 0; i < data.length; i++) {
if(identityNo == data[i]['identity_no']) {
for(var j = 0;j < data[i]['policy_code'].length;j++){
policyCodes += '<td>' + data[i]['policy_code'][j] + '</td>';
}
}
}
console.log(policyCodes);
$('#summary-table tbody tr').html(policyCodes);
});
</script>
@foreach($asm as $a)
<a href="#" class="list-group-item list-group-item-primary" id="{{ $a['identity_no'] }}" > Identity No: {{ $a['identity_no'] }} </a>
@endforeach
Hope it helps :)
You can omit that console statement, I have included that for testing purposes.
– Ayush Jain
Jan 3 at 7:35
Thanks for help,, Just some clarification.. What about the identity number,, do I populate it using AJAX as we have done with policy codes.. ?
– Martin
Jan 3 at 7:38
Yes, You are absolutely right Martin, Actually, I just forgot to mention that part of code:
– Ayush Jain
Jan 3 at 7:39
@foreach($asm as $a) <a href="#" class="list-group-item list-group-item-primary" id="{{ $a['identity_no'] }}" > Identity No: {{ $a['identity_no'] }} </a> @endforeach
– Ayush Jain
Jan 3 at 7:39
I have added that in my answer... Thanks :)
– Ayush Jain
Jan 3 at 7:40
|
show 5 more comments
try this! I know javascript only so the solution is in pure javascript and jquery I have merged both hover and click event on the button. Hope this may help
asm = [{
identity_no: '1',
policy_code: "bla bla111111111"
}, {
identity_no: "2",
policy_code: "bla bla2222222"
}, {
identity_no: "3",
policy_code: "bla bla3333"
}];
function btns() {
var btn = $("<button class='tags' id=" + asm[i].identity_no + ">" + asm[i].identity_no + "</button>");
$(btn).attr("data-search", asm[i].identity_no)
$(btn).appendTo("#buttons")
}
$('#buttons').on('click mouseover', 'button', function() {
console.log('click on', $(this).attr('id'));
var a = asm.filter(x => x.identity_no === $(this).attr('id')).map(x => x.policy_code);
console.log("found!--", a)
// show this on other side of col
});
for (i = 0; i < asm.length; i++) {
btns();
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<div id="buttons"></div>
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54017565%2fproblem-displaying-dynamic-data-in-an-array-in-laravel-blade-view-using-javascri%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can do like this(tested on my local and found it working):
<script>
var data;
$( document ).ready(function() {
data = {!! json_encode($asm) !!};
});
$(document).on("mouseenter", "a", function() {
var policyCodes = '';
var identityNo = $(this).attr('id');
for(var i = 0; i < data.length; i++) {
if(identityNo == data[i]['identity_no']) {
for(var j = 0;j < data[i]['policy_code'].length;j++){
policyCodes += '<td>' + data[i]['policy_code'][j] + '</td>';
}
}
}
console.log(policyCodes);
$('#summary-table tbody tr').html(policyCodes);
});
</script>
@foreach($asm as $a)
<a href="#" class="list-group-item list-group-item-primary" id="{{ $a['identity_no'] }}" > Identity No: {{ $a['identity_no'] }} </a>
@endforeach
Hope it helps :)
You can omit that console statement, I have included that for testing purposes.
– Ayush Jain
Jan 3 at 7:35
Thanks for help,, Just some clarification.. What about the identity number,, do I populate it using AJAX as we have done with policy codes.. ?
– Martin
Jan 3 at 7:38
Yes, You are absolutely right Martin, Actually, I just forgot to mention that part of code:
– Ayush Jain
Jan 3 at 7:39
@foreach($asm as $a) <a href="#" class="list-group-item list-group-item-primary" id="{{ $a['identity_no'] }}" > Identity No: {{ $a['identity_no'] }} </a> @endforeach
– Ayush Jain
Jan 3 at 7:39
I have added that in my answer... Thanks :)
– Ayush Jain
Jan 3 at 7:40
|
show 5 more comments
You can do like this(tested on my local and found it working):
<script>
var data;
$( document ).ready(function() {
data = {!! json_encode($asm) !!};
});
$(document).on("mouseenter", "a", function() {
var policyCodes = '';
var identityNo = $(this).attr('id');
for(var i = 0; i < data.length; i++) {
if(identityNo == data[i]['identity_no']) {
for(var j = 0;j < data[i]['policy_code'].length;j++){
policyCodes += '<td>' + data[i]['policy_code'][j] + '</td>';
}
}
}
console.log(policyCodes);
$('#summary-table tbody tr').html(policyCodes);
});
</script>
@foreach($asm as $a)
<a href="#" class="list-group-item list-group-item-primary" id="{{ $a['identity_no'] }}" > Identity No: {{ $a['identity_no'] }} </a>
@endforeach
Hope it helps :)
You can omit that console statement, I have included that for testing purposes.
– Ayush Jain
Jan 3 at 7:35
Thanks for help,, Just some clarification.. What about the identity number,, do I populate it using AJAX as we have done with policy codes.. ?
– Martin
Jan 3 at 7:38
Yes, You are absolutely right Martin, Actually, I just forgot to mention that part of code:
– Ayush Jain
Jan 3 at 7:39
@foreach($asm as $a) <a href="#" class="list-group-item list-group-item-primary" id="{{ $a['identity_no'] }}" > Identity No: {{ $a['identity_no'] }} </a> @endforeach
– Ayush Jain
Jan 3 at 7:39
I have added that in my answer... Thanks :)
– Ayush Jain
Jan 3 at 7:40
|
show 5 more comments
You can do like this(tested on my local and found it working):
<script>
var data;
$( document ).ready(function() {
data = {!! json_encode($asm) !!};
});
$(document).on("mouseenter", "a", function() {
var policyCodes = '';
var identityNo = $(this).attr('id');
for(var i = 0; i < data.length; i++) {
if(identityNo == data[i]['identity_no']) {
for(var j = 0;j < data[i]['policy_code'].length;j++){
policyCodes += '<td>' + data[i]['policy_code'][j] + '</td>';
}
}
}
console.log(policyCodes);
$('#summary-table tbody tr').html(policyCodes);
});
</script>
@foreach($asm as $a)
<a href="#" class="list-group-item list-group-item-primary" id="{{ $a['identity_no'] }}" > Identity No: {{ $a['identity_no'] }} </a>
@endforeach
Hope it helps :)
You can do like this(tested on my local and found it working):
<script>
var data;
$( document ).ready(function() {
data = {!! json_encode($asm) !!};
});
$(document).on("mouseenter", "a", function() {
var policyCodes = '';
var identityNo = $(this).attr('id');
for(var i = 0; i < data.length; i++) {
if(identityNo == data[i]['identity_no']) {
for(var j = 0;j < data[i]['policy_code'].length;j++){
policyCodes += '<td>' + data[i]['policy_code'][j] + '</td>';
}
}
}
console.log(policyCodes);
$('#summary-table tbody tr').html(policyCodes);
});
</script>
@foreach($asm as $a)
<a href="#" class="list-group-item list-group-item-primary" id="{{ $a['identity_no'] }}" > Identity No: {{ $a['identity_no'] }} </a>
@endforeach
Hope it helps :)
edited Jan 3 at 7:40
answered Jan 3 at 7:33
Ayush JainAyush Jain
1437
1437
You can omit that console statement, I have included that for testing purposes.
– Ayush Jain
Jan 3 at 7:35
Thanks for help,, Just some clarification.. What about the identity number,, do I populate it using AJAX as we have done with policy codes.. ?
– Martin
Jan 3 at 7:38
Yes, You are absolutely right Martin, Actually, I just forgot to mention that part of code:
– Ayush Jain
Jan 3 at 7:39
@foreach($asm as $a) <a href="#" class="list-group-item list-group-item-primary" id="{{ $a['identity_no'] }}" > Identity No: {{ $a['identity_no'] }} </a> @endforeach
– Ayush Jain
Jan 3 at 7:39
I have added that in my answer... Thanks :)
– Ayush Jain
Jan 3 at 7:40
|
show 5 more comments
You can omit that console statement, I have included that for testing purposes.
– Ayush Jain
Jan 3 at 7:35
Thanks for help,, Just some clarification.. What about the identity number,, do I populate it using AJAX as we have done with policy codes.. ?
– Martin
Jan 3 at 7:38
Yes, You are absolutely right Martin, Actually, I just forgot to mention that part of code:
– Ayush Jain
Jan 3 at 7:39
@foreach($asm as $a) <a href="#" class="list-group-item list-group-item-primary" id="{{ $a['identity_no'] }}" > Identity No: {{ $a['identity_no'] }} </a> @endforeach
– Ayush Jain
Jan 3 at 7:39
I have added that in my answer... Thanks :)
– Ayush Jain
Jan 3 at 7:40
You can omit that console statement, I have included that for testing purposes.
– Ayush Jain
Jan 3 at 7:35
You can omit that console statement, I have included that for testing purposes.
– Ayush Jain
Jan 3 at 7:35
Thanks for help,, Just some clarification.. What about the identity number,, do I populate it using AJAX as we have done with policy codes.. ?
– Martin
Jan 3 at 7:38
Thanks for help,, Just some clarification.. What about the identity number,, do I populate it using AJAX as we have done with policy codes.. ?
– Martin
Jan 3 at 7:38
Yes, You are absolutely right Martin, Actually, I just forgot to mention that part of code:
– Ayush Jain
Jan 3 at 7:39
Yes, You are absolutely right Martin, Actually, I just forgot to mention that part of code:
– Ayush Jain
Jan 3 at 7:39
@foreach($asm as $a) <a href="#" class="list-group-item list-group-item-primary" id="{{ $a['identity_no'] }}" > Identity No: {{ $a['identity_no'] }} </a> @endforeach
– Ayush Jain
Jan 3 at 7:39
@foreach($asm as $a) <a href="#" class="list-group-item list-group-item-primary" id="{{ $a['identity_no'] }}" > Identity No: {{ $a['identity_no'] }} </a> @endforeach
– Ayush Jain
Jan 3 at 7:39
I have added that in my answer... Thanks :)
– Ayush Jain
Jan 3 at 7:40
I have added that in my answer... Thanks :)
– Ayush Jain
Jan 3 at 7:40
|
show 5 more comments
try this! I know javascript only so the solution is in pure javascript and jquery I have merged both hover and click event on the button. Hope this may help
asm = [{
identity_no: '1',
policy_code: "bla bla111111111"
}, {
identity_no: "2",
policy_code: "bla bla2222222"
}, {
identity_no: "3",
policy_code: "bla bla3333"
}];
function btns() {
var btn = $("<button class='tags' id=" + asm[i].identity_no + ">" + asm[i].identity_no + "</button>");
$(btn).attr("data-search", asm[i].identity_no)
$(btn).appendTo("#buttons")
}
$('#buttons').on('click mouseover', 'button', function() {
console.log('click on', $(this).attr('id'));
var a = asm.filter(x => x.identity_no === $(this).attr('id')).map(x => x.policy_code);
console.log("found!--", a)
// show this on other side of col
});
for (i = 0; i < asm.length; i++) {
btns();
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<div id="buttons"></div>
add a comment |
try this! I know javascript only so the solution is in pure javascript and jquery I have merged both hover and click event on the button. Hope this may help
asm = [{
identity_no: '1',
policy_code: "bla bla111111111"
}, {
identity_no: "2",
policy_code: "bla bla2222222"
}, {
identity_no: "3",
policy_code: "bla bla3333"
}];
function btns() {
var btn = $("<button class='tags' id=" + asm[i].identity_no + ">" + asm[i].identity_no + "</button>");
$(btn).attr("data-search", asm[i].identity_no)
$(btn).appendTo("#buttons")
}
$('#buttons').on('click mouseover', 'button', function() {
console.log('click on', $(this).attr('id'));
var a = asm.filter(x => x.identity_no === $(this).attr('id')).map(x => x.policy_code);
console.log("found!--", a)
// show this on other side of col
});
for (i = 0; i < asm.length; i++) {
btns();
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<div id="buttons"></div>
add a comment |
try this! I know javascript only so the solution is in pure javascript and jquery I have merged both hover and click event on the button. Hope this may help
asm = [{
identity_no: '1',
policy_code: "bla bla111111111"
}, {
identity_no: "2",
policy_code: "bla bla2222222"
}, {
identity_no: "3",
policy_code: "bla bla3333"
}];
function btns() {
var btn = $("<button class='tags' id=" + asm[i].identity_no + ">" + asm[i].identity_no + "</button>");
$(btn).attr("data-search", asm[i].identity_no)
$(btn).appendTo("#buttons")
}
$('#buttons').on('click mouseover', 'button', function() {
console.log('click on', $(this).attr('id'));
var a = asm.filter(x => x.identity_no === $(this).attr('id')).map(x => x.policy_code);
console.log("found!--", a)
// show this on other side of col
});
for (i = 0; i < asm.length; i++) {
btns();
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<div id="buttons"></div>
try this! I know javascript only so the solution is in pure javascript and jquery I have merged both hover and click event on the button. Hope this may help
asm = [{
identity_no: '1',
policy_code: "bla bla111111111"
}, {
identity_no: "2",
policy_code: "bla bla2222222"
}, {
identity_no: "3",
policy_code: "bla bla3333"
}];
function btns() {
var btn = $("<button class='tags' id=" + asm[i].identity_no + ">" + asm[i].identity_no + "</button>");
$(btn).attr("data-search", asm[i].identity_no)
$(btn).appendTo("#buttons")
}
$('#buttons').on('click mouseover', 'button', function() {
console.log('click on', $(this).attr('id'));
var a = asm.filter(x => x.identity_no === $(this).attr('id')).map(x => x.policy_code);
console.log("found!--", a)
// show this on other side of col
});
for (i = 0; i < asm.length; i++) {
btns();
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<div id="buttons"></div>
asm = [{
identity_no: '1',
policy_code: "bla bla111111111"
}, {
identity_no: "2",
policy_code: "bla bla2222222"
}, {
identity_no: "3",
policy_code: "bla bla3333"
}];
function btns() {
var btn = $("<button class='tags' id=" + asm[i].identity_no + ">" + asm[i].identity_no + "</button>");
$(btn).attr("data-search", asm[i].identity_no)
$(btn).appendTo("#buttons")
}
$('#buttons').on('click mouseover', 'button', function() {
console.log('click on', $(this).attr('id'));
var a = asm.filter(x => x.identity_no === $(this).attr('id')).map(x => x.policy_code);
console.log("found!--", a)
// show this on other side of col
});
for (i = 0; i < asm.length; i++) {
btns();
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<div id="buttons"></div>
asm = [{
identity_no: '1',
policy_code: "bla bla111111111"
}, {
identity_no: "2",
policy_code: "bla bla2222222"
}, {
identity_no: "3",
policy_code: "bla bla3333"
}];
function btns() {
var btn = $("<button class='tags' id=" + asm[i].identity_no + ">" + asm[i].identity_no + "</button>");
$(btn).attr("data-search", asm[i].identity_no)
$(btn).appendTo("#buttons")
}
$('#buttons').on('click mouseover', 'button', function() {
console.log('click on', $(this).attr('id'));
var a = asm.filter(x => x.identity_no === $(this).attr('id')).map(x => x.policy_code);
console.log("found!--", a)
// show this on other side of col
});
for (i = 0; i < asm.length; i++) {
btns();
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<div id="buttons"></div>
answered Jan 3 at 7:32
the_ultimate_developerthe_ultimate_developer
1,022722
1,022722
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54017565%2fproblem-displaying-dynamic-data-in-an-array-in-laravel-blade-view-using-javascri%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
So what is the issue you are facing while achieving this?
– Mayank Pandeyz
Jan 3 at 6:56
@MayankPandeyz Am not sure how to display the policy codes in the table after a particular identity number is clicked or hovered on using Javascript
– Martin
Jan 3 at 6:59
@MayankPandeyz What`s your suggestion about it..
– Martin
Jan 3 at 7:13