Skip to content
Advertisement

How to add values to href in which some value are from AJAX and some from PHP loop

This above code is showing data of the selected ward.

$("#sel_ward").change(function () {
    var wardid = $(this).val();

    $.ajax({
        url: 'getWard-details.php',
        type: 'post',
        data: {ward: wardid},
        dataType: 'json',

        success: function (response) {
            var len = response.length;
            // $("#sel_ward").empty();
            if (len == 0) {
                $("#sel_ward").append('<option value="">No Data Found</option>');
                var block_selected = response[i]['block_selected'];
                $("#blockid").val(block_selected);
            } else {
                for (var i = 0; i < len; i++) {
                    var id = response[i]['id'];
                    var name = response[i]['name'];

                    var ward_parshad_name = response[i]['ward_parshad_name'];
                    var ward_parshad_contact = response[i]['ward_parshad_contact'];
                    var ward_population = response[i]['ward_population'];
                    var ward_house_count = response[i]['ward_house_count'];
                    var ward_voters_count = response[i]['ward_voters_count'];
                    var ward_polling_both_count = response[i]['ward_polling_both_count'];

                    var block_selected = response[i]['block_selected'];
                    var zone_selected = response[i]['zone_selected'];
                    var sector_selected = response[i]['sector_selected'];
                    var block_area = response[i]['block_area'];
                    var block_region = response[i]['block_region'];

                    $("#ward-name-view").text(name);
                    $("#ward-parshad-name-view").text(ward_parshad_name);
                    $("#ward-parshad-contact-view").text(ward_parshad_contact);
                    $("#ward-population-view").text(ward_population);
                    $("#ward-house-view").text(ward_house_count);
                    $("#ward-voters-view").text(ward_voters_count);
                    $("#ward-polling-booth-view").text(ward_polling_both_count);
                }
            }
        }
    });
});

Now i have list of committee whose data m getting through PHP

<?php
// Fetch Committee
$sql_block = "SELECT * FROM committee";
$block_data = mysqli_query($con, $sql_block);

while ($row = mysqli_fetch_assoc($block_data)) {
    $committeeid = $row['sno'];
    $committee_name = $row['committee_name'];
    ?>
    <a id=committee href=""><span><?= $committee_name ?></span></a>
<?php } ?>

Now what i want is as soon as 1 of the committee is selected.. i want to take data from ward details as well as the committee id and name to the next page. THis will provide much clear view

Advertisement

Answer

<input type=hidden id=committee_id value=<?=$committeeid?>>
<input type=hidden id=committee_name value=<?=$committee_name?>>


    var committeeid = $("#committee_id").val();
 $("#committee").click(function(){
window.open("index.php?id="+committeeid+"", '_blank');
 });

I used input tag to store the value and marked it as hidden. Then on click of committee item i fetched data from input and use it accordingly.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement