Jump to content

Dropdown box help.


01hanstu

Recommended Posts

Hi, i have a dropdown box that is populated. The user has to click go and i would like it to navigate automatically. My code populates the information from MySql

 

<?

$getroomsquery = "SELECT * from rooms";

$getroomresults = mysql_query($getroomsquery);

$getroomcount = mysql_num_rows($getroomresults);

$loop = 0;

?>

        <form name="roomform" method="post" action="bookingindex.php?week=<? print $mondaythisinstance ?>">

          <select name="selectroom" class="formnames">

              <option value=" <?PHP print $room ?>" selected>Selected: <?PHP print $room ?></option>

<option value="">- - - - - - - - - - -</option>

  <? while ($loop < $getroomcount)

            {

print"<option value=\"".mysql_result($getroomresults,$loop,"roomname")."\">".mysql_result($getroomresults,$loop,"roomname")."</option>";

            $loop ++;

}

?>

 

I would like to know how i can change this so it will become automated.

 

Help is appreciated

Stuart

Link to comment
Share on other sites

Hi, sorry what i mean by automatic is that when the user selects an item from the list is takes them to the link (getting rid of the go button). So for example if a user selects google from the dropdown it will take them to google and they don't have to press go.

Link to comment
Share on other sites

True this looks like a javascript fix, this might be helpfull

<script language="javascript" type="text/javascript">
function popitup(url) {
  newwindow=window.open(url,'name','height=200,width=150');
  if (window.focus) {newwindow.focus()}
  return false;
}
</script>
<? 
  $getroomsquery = "SELECT * from rooms";
  $getroomresults = mysql_query($getroomsquery);
  $getroomcount = mysql_num_rows($getroomresults);
  $loop = 0;
?>   
  <form name="roomform" method="post" action="bookingindex.php?week=<? print $mondaythisinstance ?>">
    <select name="selectroom" class="formnames">
  <option value=" <?PHP print $room ?>" selected>Selected: <?PHP print $room ?></option>
      <option value="">- - - - - - - - - - -</option>
      <? while ($loop < $getroomcount) 
    {
          print"<option value=\"".mysql_result($getroomresults,$loop,"roomname")."\" onClick=\"popitup(this.value)\">".mysql_result($getroomresults,$loop,"roomname")."</option>";
      $loop ++;
         }
?>

 

 

Link to comment
Share on other sites

I've done a quick test case and it works fine, what error are you getting??


<script language="javascript" type="text/javascript">
function popitup(url) {
  newwindow=window.open(url,'name','height=200,width=150');
  if (window.focus) {newwindow.focus()}
  return false;
}
</script>
<?

  $getroomcount = 2;
  $loop = 0;
?>   
  <form name="roomform" method="post" action="bookingindex.php?week=<? print $mondaythisinstance ?>">
    <select name="selectroom" class="formnames">
     <option value=" <?PHP print $room ?>" selected>Selected: <?PHP print $room ?></option>
      <option value="">- - - - - - - - - - -</option>
      <? while ($loop < $getroomcount)
       {
          print"<option value=\"".rand(1,100)."\" onClick=\"popitup(this.value)\">Here</option>";
         $loop ++;
         }
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.