Is it possible to pass values from PHP to a modal box using plain Javascript? I researched here in SO and found that most of the answers are either JQuery or AJAX. I'd like to know how because I'm new in Javascript and PHP so I'd like to first have a thorough practice and understanding in Javascript before diving into JQuery and AJAX.
I'm working on a small project which has a modal box and a <table> with an Edit control.
<div id="modalBox" class="w3-modal">
<div class="w3-modal-content">
<div class="w3-container">
<span onclick="document.getElementById('modalBox').style.display='none'" class="w3-button w3-display-topright">×</span>
<p>Some text. Some text. Some text.</p>
<p>Some text. Some text. Some text.</p>
</div>
</div>
</div>
<div class="record-container">
<table class="table-record">
<tr>
<th>Title</th>
<th>Date Created</th>
<th>Control</th>
</tr>
<?php
$announcementDaoImpl = new AnnouncementDaoImpl($pdo);
$announcementList = $announcementDaoImpl->getAllAnnouncementByMostRecent();
foreach($announcementList as $key => $value): ?>
<tr>
<td><?php echo $key->getTitle(); ?></td>
<td><?php echo $value->getDateAdded(); ?></td>
<td>
<a href="#" onclick="showEditModal('modalBox')">Edit</a>
</td>
</tr>
<?php endforeach; ?>
</table>
</div>
Let's say I want to fill the modal box with the value returned by $value->getDateAdded, is that possible without JQuery and AJAX?
How can I go about it? Can you provide some ideas.
Thank you.
showEditModalcould store the value in an html data attribute, and then retrieve when the modal javascript code executes.showEditModal()function and pass the value of $value->getDateAdded to that.$valueobject to javascript functionshowEditModel()then from within the method's block I like to access theget()methods. I can't figure out how to do that usingjson_encode