Abdul Waheed Abdul Waheed - 1 year ago 71
Javascript Question

How to show check box text if it is not next to check box using jQuery

I am trying to achieve checked value text should visible like shown in the image:

 image here

Without refresh or any click can anyone help me out?

This is my php dynamic from :

<div class="products-row">
<?php $tq=$conn->query("select * from os_tiffen where tiffen_status=1 order by id_tiffen ASC");
while ($tiffen = $tq->fetch_assoc()) {
<div class="col-md-3">
<div class="foodmenuform row text-center">
<input multiple="multiple" type="checkbox" id="<?php echo $tiffen['tiffen_image']; ?>" name="tifeen" hidden>
<label for="<?php echo $tiffen['tiffen_image'];?>"><img src="img/tiffen/<?php echo $tiffen['tiffen_image']; ?>" class="img img-responsive" /></label>
<h3 class="FoodName"><?php echo $tiffen['tiffen_name'];?></h3>
<?php } ?>

This is my script to show the text:

<script type="text/javascript" language="JavaScript">
$( document ).ready(function() {
var FoodMenu = $('input[type=checkbox]:checked').map(function(){
return $(this).next('.FoodName').text();

Out put id:
<a id="selectedfood"></a></li>

Answer Source

You could try to get all checked options’ text on checkbox change event and append selected values to “selectedfood”. The following sample code is for your reference.

$(function () {
    $(".foodmenuform [type='checkbox']").change(function () {

        var FoodMenu = "";
        var ischecked = $(".foodmenuform [type='checkbox']:checked").each(function () {

            FoodMenu += $(this).siblings(".FoodName").text() + "<br/>";

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download