Robert
Robert

Reputation: 147

modal popup in javascript

I have a checkbox, which is inside a modal popup div.I want the check box value when the checkbox is checked and want to place the value to a div which is outside the modal popup box.Please help me to find a solution. Please find the code below

<div class="container">
    <div id="test"></div> 
    <h2>Modal popup</h2> 
    <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button> 
    <div class="modal fade" id="myModal" role="dialog"> 
        <div class="modal-body"> 
            <input type="checkbox" class="ck " id="mealstotal" value="12"> 
        </div> 
        <div class="modal-footer"> 
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> 
        </div> 
    </div> 
</div> 

Upvotes: 0

Views: 202

Answers (1)

Alex Mac
Alex Mac

Reputation: 2993

Please find below mentioned solution. This will help you.

$(document).on('change','#item',function(){
   if($(this).prop('checked') == true){
      $('#result').html($(this).val());
   }else{
      $('#result').html('');
   }
});
div {border:1px solid red; width:100%; padding:10px;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<input type="checkbox" name="item" id="item" value="1" /> Checkbox

<div id="result"></div>

Let me know if it not works.

Upvotes: 1

Related Questions