Link to home
Start Free TrialLog in
Avatar of Aleks
AleksFlag for United States of America

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Aleks

ASKER

Great thanks !