-1

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!

Bizley
  • 17,392
  • 5
  • 49
  • 59
Mael
  • 21
  • 5
  • You are looking for ajax. – jeroen Dec 12 '16 at 11:09
  • use jQuery.ajax() method provided by jquery......it is the easiest and the best way to get a value and pass it without performing any reloading. `http://api.jquery.com/jquery.ajax/` – abhit Dec 12 '16 at 11:09

1 Answers1

0

This is how you take a value from a textbox in jquery.

$("#roomNo").val()

Also, ajax will help you to communicate with server side and see the results without refreshing the page.

kchr
  • 1
  • 3
  • How can I pass it here in query? $con = mysqli_connect("localhost","root","","acmh"); $sql = "SELECT * FROM tblroom INNER JOIN tblbed ON tblroom.roomID = tblbed.roomID WHERE = tblroom.roomID"; $result = mysqli_query($con,$sql); while($row = mysqli_fetch_array($result)):?> – Mael Dec 12 '16 at 14:55
  • http://stackoverflow.com/questions/13447554/how-to-get-input-field-value-using-php – kchr Dec 12 '16 at 15:19
  • check this link, i think that it can help – kchr Dec 12 '16 at 15:20