Hello, i wanna ask you guys if there is anyway i can get the value of a dropdown and pass it to another php file without using the <input type="submit> way?
The way is i have the options in my menu coming from the database
This is my code on the dropdown menu

mysql_connect("localhost", "root" , "");
$query3 = "SELECT suite_code from tblsuite WHERE suite_name = '".$suitename."'";
$result3 = mysql_query($query3);
$row3 = mysql_fetch_assoc($result3);
$suite = $row3['suite_code'];
mysql_connect("localhost", "root" , "");
$queryroom = "SELECT * from tblroom WHERE room_accommodation = '" . $suite . "' AND status = 'AVAILABLE'";
$resultroom = mysql_query($queryroom);

if ($resultroom && mysql_num_rows($resultroom) > 0)
echo '<form name = "room" method = "get" action = "reserveupdate.php">';
echo '<select name = "room" id = "rooms">';
while($rows = mysql_fetch_assoc($resultroom))
echo '<option>' . $rows['room_no'] . '</option>';
echo '</select></form>';

i have no problem on this one, the problem is i am trying to select the text of the dropdown and pass it to another php file which have this code

if (isset($_GET['room'])){
$query = "UPDATE tblreserve SET room_no = '" .$_GET['room']. "', status = 'APPROVED' WHERE reservation_code = '" . $reser . "'";
$res = mysql_query($query);

$query2 = "UPDATE tblroom SET status = 'OCCUPIED' WHERE room_no = '" . $_GET['room'] . "'";
$res2 = mysql_query($query2);

echo "<script>alert('Reservee Approved!'); window.location = './adminreserve.php';</script>";

i don't want to use the submit for some circumstances, anyone can help?

4 Years
Discussion Span
Last Post by broj1

No, the only way you could dynamically pass it without submitting is to use some AJAX and JavaScript, unfortunately it cannot be done with PHP alone as it is rendered server side before the page is even displayed.


Is it only that you do not want to to have a submit button or do you not want to reload the page?

In first case you can use onchange event of the select (dropdown).

echo '<select name="room" id ="rooms" onChange="this.submit()">';

The form wil get submitted once you select an option and you do not need a submit button.

In you do not want to reload the page then use Ajax as AHarrisGsy suggested. Ajax is simple to use if you use jQuery. See this link.


@broj: it's not that i dont want to reload my page, this code is a table that calls each data and displays it row by row using loop until all datas are called, i have a label (each row) that have the a href = page.php?id='id of the user in each row' function and i cant use submit since the href wont work anymore. But in this row, i need to change the room number but it is in the dropdown and i don't know how to get the text of the dropdown without using the submit type.

hope you get what i am trying to say.


Just to make things more clear: does each row contain information for different user (user id) or are all rows for the same user?


It seems Ajax would be appropriate for this. So on selecting a dropdown the room number would be changed in database but the page would still display the table and the URLs with user IDs. Is this correct?


Solved it already, thank you for replying back. ill post here again if i encounter any problem
Once again, thank you :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.