I think the best solution is the onChange
function but it's really confusing on how to use it.
Scenario: I have a search button which has a modal inside. After selecting the value, the value will be put in a textbox which is I already did.
This comes from the database called tblroom which is the primary key is the room ID.
Now, I want the value inside the textbox to use it again to another query to search for the beds (this bed comes from the database called tblbed where the foreign key is the roomID coming from the tblroom). Without reloading the page or using submit in form.
<div class="form-group">
<label for="roomNo">Room Number:</label>
<input style="margin-left: 60px;text-align: center; width: 40%;" name="roomNo" id="roomNo" type="text" class="form-control form-control-inline" readonly required>
<button style="margin-left: 10px" type="button" class="btn btn-primary" data-toggle="modal" data-target="#roomModal"><span class="glyphicon glyphicon-search"></span>Search</span></button>
</div>
<div class="form-group">
<label for="roomNo">Bed Number:</label>
<input style="margin-left: 60px;text-align: center; width: 40%;" name="roomNo" id="roomNo" type="text" class="form-control form-control-inline" readonly required>
<button style="margin-left: 10px" type="button" class="btn btn-primary" data-toggle="modal" data-target="#bedModal"><span class="glyphicon glyphicon-search"></span>Search</span></button>
</div>
Here's my query for the roomNumber
<table class="table table-hover">
<thead>
<tr>
<th width="10%">Room ID</th>
<th style="text-align:center">Description</th>
<th width="14%">Bed Capacity</th>
<th style="text-align:center" width="20%">Room Rate</th>
<th width="10%">Status</th>
<th width="15%">Action</th>
</tr>
</thead>
<tbody>
<?php
$con = mysqli_connect("localhost","root","","acmh");
$sql = "SELECT roomID, bedCapacity, Status, roomrate, description FROM tblroom
INNER JOIN tblroomtype ON tblroom.roomtypeID = tblroomtype.roomtypeID ORDER BY roomID";
//Bed Number
//$sql2 = "SELECT bedNumber, roomID, Status FROM tblbed INNER JOIN tblroom ON tblroom.roomID = tblbed.roomID ORDER BY bedNumber";
$result = mysqli_query($con,$sql);
while($row = mysqli_fetch_array($result)):
?>
<tr onclick="getRoomid(this);">
<?php
<td style="text-align:center"><?= $row['roomID']; ?></td>
<td><?= $row['description']; ?></td>
<td style="text-align:center"><?= $row['bedCapacity']; ?></td>
<td style="text-align:center"><?= $row['roomrate']; ?></td>
<td><?= $row['Status']; ?></td>
<td>
<button onclick="getRoomid(this);" name="room" value="<?= $row['roomID']; ?>" type="button" class="btn btn-primary" data-dismiss="modal">Select</button>
</td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
I want to create another one like this but the I will be using the value from the room to equals it in Query.
Like this
$sql = "SELECT
bedNumber, roomID FROM tblroom
INNER JOIN tblbed ON tblroom.roomID = tblbed.roomID
WHERE tblroom.roomID = (VALUE OF THE TEXTBOX FROM THE ROOM NO)";
I hope that this one's is not confusing. I have been really searching for this for 5 days and I can't find the answer. Any help and advice will do. Thank you!