2017-03-02 13 views
0

私はjavascript関数に値idを渡します。idは印刷しています。javascriptからcodeigniterのブートストラップモデルにidを渡す方法は?

<script> 
    function openModal(id) { 
    document.getElementById('myModal').style.display = "block"; 
    var img_id = id; 
    document.getElementById('caption').innerHTML = img_id; 
    } 
</script> 

が、今私は、ブートストラップモーダル

<div id="myModal" class="modal"> 
    <button type="button" id="close" onclick="closeModal()">close</button> 

    <div class="modal-content"> 
    <div class="mySlides"> 

    <?php  

    //here i want to use this id with if condition so that desired image is 
    //displayed.With for each all images are coming. 
    //$project_images = explode(",", $value['project_gallery']); 

    $project_images = json_decode($value['project_gallery'],true); 

    foreach ($project_images as $project_image_value) { 
    ?> 

    <img src="<?= base_url() ?>assets/uploads/projects/<? =$project_image_value['fname']?>" style="width:100%"> 

    <?php 
    } 
    ?> 
    </div> 
</div> 
</div> 

にこの値を渡したいそれはそう私に知らせて.IF可能です。

+0

あなたはもっと具体的になることができますか? – user218046

+0

私はモデルで使用するように、javascript関数からimg_idをブートストラップモデルに渡したい –

+0

正確にそのIDをモデルにしたいですか? – user218046

答えて

0

スクリプト

<input type="hidden" id="img_id" name="img_id"> 

のようにブートストラップモーダルに1つの隠しフィールドを追加し、追加

function openModal(id) { 
$("#img_id").val(id); 
document.getElementById('myModal').style.display = "block"; 
var img_id = id; 
document.getElementById('caption').innerHTML = img_id; 

}あなたが

合格する値を持つ1フィールドimg_idを得るモデルでそう

+0

PHPを使用して入力を隠して値を取得する方法 –

+0

js変数をPHPに送るためにGET/POSTを使用する必要があります –

+0

私は理解しませんでした。あなたは精巧になりますか? –

関連する問題