Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing PHP Values to Bootstrap 3 Modal
    primarykey
    data
    text
    <p>I am trying to pass PHP values from the DB to a bootstrap modal which is a form that posts to some other page, I think I am close but i can't figure out why the bootstrap modal -text box won't the values from PHP, I followed Ashish's article and got very close, but just not able to get the values to the bootstrap modal.</p> <p>Thanks in advance.</p> <p>Below is the HTML and the PHP part of the code.</p> <pre><code>&lt;table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered datatables" id="example"&gt; &lt;thead&gt; &lt;tr&gt; &lt;th&gt;Sr.No&lt;/th&gt; &lt;th&gt;Customer Name&lt;/th&gt; &lt;th&gt;Email&lt;/th&gt; &lt;th&gt;Cell&lt;/th&gt; &lt;th&gt;Appointment On&lt;/th&gt; &lt;th&gt;Modify Status&lt;/th&gt; &lt;th colspan="2"&gt;Actions&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;?php while($row=mysql_fetch_array($getenqs)) { echo '&lt;tr&gt;'; echo '&lt;td&gt;'.$cnt.'&lt;/td&gt;'; echo '&lt;td&gt;'.$row['custname'].'&lt;/td&gt;'; echo '&lt;td&gt;'.$row['custemail'].'&lt;/td&gt;'; echo '&lt;td&gt;'.$row['custcell'].'&lt;/td&gt;'; echo '&lt;td&gt;'.datemaker($row['enq_date']).'&lt;/td&gt;'; echo '&lt;td align="center"&gt;&lt;a data-toggle="modal" data-enid'.$cnt.'="'.$row['id'].'" href="#addappModal'.$cnt.'" class="caddappModal'.$cnt.'"&gt;&lt;i class="fa fa-calendar showgreen"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/td&gt;'; echo '&lt;td align="center"&gt;&lt;a data-toggle="modal" href="#modstatModal"&gt;&lt;i class="fa fa-pencil showgreen"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/td&gt;'; echo'&lt;td align="center"&gt;&lt;a class="tooltips" data-toggle="tooltip" data-placement="left" title="Add as a Member" href="ajax/add-as-member?enqid='.$row['id'].'"&gt;&lt;i class="fa fa-share showgreen"&gt;&lt;/i&gt;&lt;/a&gt;'; echo'&lt;td align="center"&gt;&lt;a class="tooltips" data-toggle="tooltip" data-placement="left" title="Hide this enquiry" href="ajax/hide-enquiry?enqid='.$row['id'].'"&gt;&lt;i class="fa fa-minus-circle showgreen"&gt;&lt;/i&gt;&lt;/a&gt;'; echo '&lt;/tr&gt;'; ?&gt; &lt;!-- Modal to Add Appointments--&gt; &lt;form action="addapp" class="form-horizontal row-border" data-validate="parsley" id="validate-form"&gt; &lt;div class="modal fade" id="addappModal&lt;?php echo $cnt;?&gt;" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"&gt; &lt;div class="modal-dialog"&gt; &lt;div class="modal-content"&gt; &lt;div class="modal-header panel-green"&gt; &lt;button type="button" class="close" data-dismiss="modal" aria-hidden="true"&gt;&amp;times;&lt;/button&gt; &lt;h4 class="modal-title"&gt;Add an Appointment for &lt;?php echo $row['custname']; ?&gt;&lt;/h4&gt; &lt;/div&gt; &lt;div class="modal-body" id="addapp" &gt; &lt;div class="form-group"&gt; &lt;label class="col-sm-3 control-label"&gt;Required Field&lt;/label&gt; &lt;div class="col-sm-6"&gt; &lt;input type="text" required="required" class="form-control" id="datepicker"&gt; &lt;input type="text" name="enid" id="fenid&lt;?php echo $cnt;?&gt;"&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="modal-footer"&gt; &lt;div class="row"&gt; &lt;div class="col-sm-6 col-sm-offset-3"&gt; &lt;div class="btn-toolbar"&gt; &lt;button class="btn-green btn" id="demoskylo" onclick="javascript:$('#validate-form').parsley( 'validate' );"&gt;&amp;nbsp;Add Appointment&lt;/button&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;&lt;!-- /.modal-content --&gt; &lt;/div&gt;&lt;!-- /.modal-dialog --&gt; &lt;/div&gt; &lt;/form&gt;&lt;!-- /.modal to add appointments ends--&gt; &lt;?php $cnt++; } ?&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>This is the jQuery code:</p> <pre><code>&lt;script&gt; $(document).ready(function(){ for(var i=1; i&lt;=&lt;?php echo $cnt;?&gt;; i++) { $('a.caddappModal'+i).click(function(){ var enid = $(this).data('enid'+i); $('#fenid'+i).val(enid); }); } }); &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload