By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 1,279 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

Drop down menus

P: n/a
Hi everybody, I have a little problem with drop down menus. I have a PHP
page in which I extract some categories (from a database). I put those
categories in a drop down menu without problems. I would like that when
a category is chosen, the entire page should be reloaded without the
pression of any "submit" button, and should appear a new drop down menu.
The main problem is the reloading of the page as it appears not to work
if, after OPTION VALUE, I put the name of the same page in which there
is the forum (entrate_in.php). Infact it say "page not found" while it
works perfectly if I put the name of a different php page... how to
resolve this problem?

<?
echo "<tr>";
echo "<td width='20%' bgcolor='#C0C0C0' align='right'> <p
align='right'>Tipo</td>";
echo "<td width='80%'> <select ONCHANGE='location =
this.options[this.selectedIndex].value;' name='tipo' id='tipo'>";

$query = mysql_query("SELECT * FROM categorie ORDER BY categoria");
$numrows = mysql_num_rows($query);

for ($i=0; $i<$numrows; $i++)
{
$row = mysql_fetch_row($query);
list($id, $categ, $col1, $col2, $col3) = $row;
echo "<option value=\"entrate_in.php?Nome=$categ\">$categ</option>";}
echo "</select></td>";
echo "</tr>";?>

THANK YOU!
Jan 15 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Capitan Catarro wrote:
Hi everybody, I have a little problem with drop down menus. I have a PHP
page in which I extract some categories (from a database). I put those
categories in a drop down menu without problems. I would like that when
a category is chosen, the entire page should be reloaded without the
pression of any "submit" button, and should appear a new drop down menu.
The main problem is the reloading of the page as it appears not to work
if, after OPTION VALUE, I put the name of the same page in which there
is the forum (entrate_in.php). Infact it say "page not found" while it
works perfectly if I put the name of a different php page... how to
resolve this problem?


Post only what the client gets, we can only guess what the result of
your PHP code is.

It is generally a bad idea to use onchange with a select element - in
IE, if you tab to the select then use the down arrow key to select an
option, onchange is fired every time you go to a new option. In the
scenario above, every time the user presses the down arrow to navigate
to the next option down, the page will re-load and they'll be back to
option 1.

Try the demo below.

To reload the current page, modify an attribute of the location object
or call its reload method:

<URL:http://developer.mozilla.org/en/docs/DOM:window.location>
<script type="text/javascript">
function reloadPage(sel)
{
window.location.search = '?' + sel.options[sel.selectedIndex].text;
}
</script>

<form action="">
<select onchange="reloadPage(this);">
<option>Option 1
<option>Option 2
<option>Option 3
</select>
</form>

[...]
--
Rob
Jan 16 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.