1,105,177 Community Members

Getting the text of the dropdown without using submit

akuteru
Newbie Poster
4 posts since Mar 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
Unverified Member
 
0
 

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" , "");
mysql_select_db("hotelgal");
$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" , "");
mysql_select_db("hotelgal");
$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?

Member Avatar
Octet
Posting Pro
579 posts since Nov 2011
Reputation Points: 45 [?]
Q&As Helped to Solve: 53 [?]
Skill Endorsements: 16 [?]
Featured
Sponsor
 
0
 

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.

Member Avatar
broj1
Posting Virtuoso
1,576 posts since Jan 2011
Reputation Points: 220 [?]
Q&As Helped to Solve: 218 [?]
Skill Endorsements: 21 [?]
Featured
 
1
 

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.

akuteru
Newbie Poster
4 posts since Mar 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
Unverified Member
 
0
 

@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.

Member Avatar
broj1
Posting Virtuoso
1,576 posts since Jan 2011
Reputation Points: 220 [?]
Q&As Helped to Solve: 218 [?]
Skill Endorsements: 21 [?]
Featured
 
0
 

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

akuteru
Newbie Poster
4 posts since Mar 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
Unverified Member
 
0
 

each row has different information (unique userids)

Member Avatar
broj1
Posting Virtuoso
1,576 posts since Jan 2011
Reputation Points: 220 [?]
Q&As Helped to Solve: 218 [?]
Skill Endorsements: 21 [?]
Featured
 
0
 

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?

akuteru
Newbie Poster
4 posts since Mar 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
Unverified Member
 
0
 

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

Member Avatar
broj1
Posting Virtuoso
1,576 posts since Jan 2011
Reputation Points: 220 [?]
Q&As Helped to Solve: 218 [?]
Skill Endorsements: 21 [?]
Featured
 
0
 

No problem, happy coding :-)

Question Answered as of 1 Year Ago by broj1 and Octet
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article