Aralanthir
11-23-2002, 12:45 AM
Hey,
I currently have PHP running to retrieve data from a MySQL database and put it in a drop-down list. The problem is, I'm trying to have the browser automatically re-direct to the URL after the user selects another option. However, for some reason, the script won't work. Here's my code:
include ('connect.php') // connect to db
include ('sql_info.php'); // sql query
$results = mysql_query( $sql );
if ( $results != false )
{
echo "<center><form name='chapters'><select name='list' onChange=\"top.location='index.php?go=3&id=$ficid&chapter='+document.chapters.list.options[document.chapters.list.selectedIndex].value;\">";
while ( $data = mysql_fetch_assoc( $results ) )
{
echo "<option value=\"";
echo $data['chapter'];
echo "\">";
echo $data['chapter'];
echo ". ";
echo $data['ctitle'];
echo "</option>";
}
echo "</select></form></center>";
}
else
{
echo mysql_error();
}
--------------------
The source code after the page has been run looks like this:
<center><form name='chapters'><select name='list' onChange="top.location='index.php?go=3&id=40&chapter='+document.chapters.list.options[document.chapters.list.selectedIndex].value;"><option value="1">1. Chapter I</option><option value="2">2. Chapter II</option><option value="3">3. Chapter III</option></select></form></center>
-----------------------
What exactly am I doing wrong? It won't re-direct the user to another page and it keeps telling me that 'document.chapters.list' has no properties.
Help?
I currently have PHP running to retrieve data from a MySQL database and put it in a drop-down list. The problem is, I'm trying to have the browser automatically re-direct to the URL after the user selects another option. However, for some reason, the script won't work. Here's my code:
include ('connect.php') // connect to db
include ('sql_info.php'); // sql query
$results = mysql_query( $sql );
if ( $results != false )
{
echo "<center><form name='chapters'><select name='list' onChange=\"top.location='index.php?go=3&id=$ficid&chapter='+document.chapters.list.options[document.chapters.list.selectedIndex].value;\">";
while ( $data = mysql_fetch_assoc( $results ) )
{
echo "<option value=\"";
echo $data['chapter'];
echo "\">";
echo $data['chapter'];
echo ". ";
echo $data['ctitle'];
echo "</option>";
}
echo "</select></form></center>";
}
else
{
echo mysql_error();
}
--------------------
The source code after the page has been run looks like this:
<center><form name='chapters'><select name='list' onChange="top.location='index.php?go=3&id=40&chapter='+document.chapters.list.options[document.chapters.list.selectedIndex].value;"><option value="1">1. Chapter I</option><option value="2">2. Chapter II</option><option value="3">3. Chapter III</option></select></form></center>
-----------------------
What exactly am I doing wrong? It won't re-direct the user to another page and it keeps telling me that 'document.chapters.list' has no properties.
Help?
