Passing values to modal window (jqyer / bootstrap)

I am trying to pass values (TRUE OR FALSE) to fields on a modal window.
This is for "field3" and "field4"

the value shows just fine on the text fields but doesn't work well with the radio buttons. I need for the radio buttons to appear marked depending on the value. (1 or 0)

This is my modal window code:

<!-- modal window -->
<div id="edit-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content animated fadeIn">

<form action="attachments_SPedit.asp" method="post" class="form-horizontal" id="form1" form="form1">
<div class="modal-header">
	<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
	<h3 class="modal-title">Edit attachment</h3><small>Please update the attachment information</small>
</div>
<div class="panel-body">
	<div class="ibox float-e-margins">
    	<div class="form-group"><label class="col-sm-3 control-label">Description</label>
        <div class="col-sm-9">
        <input name ="field1" type="text" class="form-control" id = "field1" placeholder="" value="" maxlength="50">
        </div>  
	</div>
    <div class="form-group"><label class="col-sm-3 control-label">Uploaded on</label>
        <div class="col-sm-9">
        <input name ="field2" type="text" class="form-control" id = "field2" placeholder="mm/dd/yyyy" value="" maxlength="10">
        </div>  
	</div>
     <div class="form-group"><label class="col-sm-3 control-label">Visible employer</label>
        <div class="col-sm-9">
        <input name ="field3" type="text" class="form-control" id = "field3" placeholder="" value="" maxlength="10">
        </div>  
	</div>
     <div class="form-group"><label class="col-sm-3 control-label">Visible contact</label>
        <div class="col-sm-9">
        <input name ="field4" type="text" class="form-control" id = "field4" placeholder="" value="" maxlength="10">
        </div>  
	</div>

                 <div class="form-group">
              <label class="col-sm-3 control-label">Visible to employer</label>
              <div class="col-sm-9">
                <div class="i-checks">
                  <label>
                    <input id = "field3" name="field3" type="radio" form="form1" value="1"  />
                    Yes</label>
                    
                  <label>
                    <input id = "field3" name="field3" type="radio" form="form1"  value="0" />
                    No </label>
                  
                </div>
              </div>
            </div>
     
 <div class="form-group">
              <label class="col-sm-3 control-label">Visible to contact</label>
              <div class="col-sm-9">
                <div class="i-checks">
                  <label>
                    <input id = "field4" name="field4" type="radio" form="form1" value="1"  />
                    Yes</label>
                    
                  <label>
                    <input id = "field4" name="field4" type="radio" form="form1"  value="0" />
                    No </label>
                  
                </div>
              </div>
            </div>
       
	</div>
</div>             

<div class="modal-footer">
 		<input type="hidden"  id = "idfield" name ="idfield" >
        <input name ="caseid" type="hidden"  id = "caseid" value="<%=(rs_case.Fields.Item("id").Value)%>" >
	<button type="button" class="btn btn-white" data-dismiss="modal">Close</button>
	<button type="submit" class="btn btn-primary" id = "mdlsave"  name = "mdlsave" >Save changes</button>
</div>
</form>
		</div>
	</div>
</div>
<!-- modal window end -->

Open in new window


This is the code that passes the values to the modal window. It works fine, the text fields show the value just fine but the radio buttons don't appear marked when the value is passed to them. Any clues ?

<script type="text/javascript">
 $(function () {
   $('#edit-modal').on('show.bs.modal', function(e) {  // NAME OF MODAL WINDOW TO OPEN 
     var $modal = $(this),
         esseyId = $(e.relatedTarget).data('id');  // SEND VALUE OF ID 
		 field4 = $(e.relatedTarget).data('field4');  // SEND VALUE OF FIELD 1
		 field3 = $(e.relatedTarget).data('field3');  // SEND VALUE OF FIELD 1
         field2 = $(e.relatedTarget).data('field2');  // SEND VALUE OF FIELD 1
         field1 = $(e.relatedTarget).data('field1');  // SEND VALUE OF FIELD 2 
		 
     $('input[name="idfield"]', $modal).val(esseyId); // SEND VALUE OF ID TO HIDDEN FIELD ID
console.log('[' + field1 + ']');// SEND VALUE TO DROP DOWN MENU
	$('#field1').val(field1); // SEND VALUE TO DROP DOWN MENU
	$('input[name="field2"]', $modal).val(field2); // SEND VALUE TO TEXT FIELD  
	$('input[name="field3"]', $modal).val(field3); // SEND VALUE TO TEXT FIELD  
	$('input[name="field4"]', $modal).val(field4); // SEND VALUE TO TEXT FIELD  
     $modal.find('.edit-content').html(esseyId);  
   });
   
 });
 </script>

Open in new window

LVL 1
AleksAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

leakim971PluritechnicianCommented:
Test page : https://jsfiddle.net/v1e907tf/

 $(function () {
     $(":button").click(function() {
		$("#edit-modal").show();
     });
   $('#edit-modal').on('show.bs.modal', function(e) {  // NAME OF MODAL WINDOW TO OPEN 
     var $modal = $(this),
         esseyId = $(e.relatedTarget).data('id');  // SEND VALUE OF ID 
		 field4 = $(e.relatedTarget).data('field4');  // SEND VALUE OF FIELD 1
		 field3 = $(e.relatedTarget).data('field3');  // SEND VALUE OF FIELD 1
         field2 = $(e.relatedTarget).data('field2');  // SEND VALUE OF FIELD 1
         field1 = $(e.relatedTarget).data('field1');  // SEND VALUE OF FIELD 2 
		 
     $('input[name="idfield"]', $modal).val(esseyId); // SEND VALUE OF ID TO HIDDEN FIELD ID
console.log('[' + field1 + ']');// SEND VALUE TO DROP DOWN MENU
	$('#field1').val(field1); // SEND VALUE TO DROP DOWN MENU
	$('input[name="field2"]', $modal).val(field2); // SEND VALUE TO TEXT FIELD  
	$('input[name="field3"]:eq(' + (field3*1?1:2) + ')', $modal).attr("checked", true); // SEND VALUE TO TEXT FIELD  
	$('input[name="field4"]:eq(' + (field4*1?1:2) + ')', $modal).attr("checked", true); // SEND VALUE TO TEXT FIELD  
     $modal.find('.edit-content').html(esseyId);  
   });
   
 });

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AleksAuthor Commented:
Great thanks !
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.