PDA

View Full Version : javascript navigation


red_rose
01-15-2007, 02:25 AM
hello there,

i have two problems here.

firstly, i can't retrieve the instituition name from the database in the dropdown menu. i can only see "Select Instituition". i dont know what's wrong with my code.

secondly, when the user select an option, i want the user to be redirected to the college page (let say college.php) which displays the college information. as i mentioned above, the college names are retrieved from the database ( but i failed in that). this college page is same for all the colleges, what i mean here is that, if user select option College A, then college.php will display information from the database about College A and if it's College B then college.php will show about College B.

can you guide me on how to do this? and can you tell me what's wrong in my code for my first problem.


<?php

/////////////////////////////////////
$database = "services";
$username = "root";
$password = "sa";
/////////////////////////////////////

$link = @mysql_connect('localhost', $username, $password);
$db = mysql_select_db($database, $link);

@$inst = $_POST['inst'];

if($inst) {
///////////////////////////////////////////////////////////////////////////
$query = sprintf("SELECT * FROM instituition");
$result = @mysql_query($query);
$row = mysql_fetch_array($result);
///////////////////////////////////////////////////////////////////////////
}

?>

<html>
<head>
<title>:: Welcome to Student Services System ::</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script language="javascript" type="text/javascript">

function goto() {

var win = document.getElementById('inst');
document.location.href="newpage.php";

return false;
}

</script>
</head>
<body>

<form name="form1" method="post" action="newpage.php">
<select name="inst">
<option value="" selected>Select Instituition</option>
<?php do { ?>
<option value="<?php echo @$row['Inst_Id']; ?>"><?php echo @$row['InstName']; ?></option>
<?php } while ($row = mysql_fetch_array($result)); ?>
</select>
<input name="Go" type="submit" id="Go" value="Go" onClick="goto()">
</form>

</body>
</html>

davidj
01-15-2007, 06:22 AM
first thing is you still have your button as a submit. When using JS you should use a button

you were referencing your field but not the value nor were you using it

<?php

/////////////////////////////////////
$database = "services";
$username = "root";
$password = "sa";
/////////////////////////////////////

$link = @mysql_connect('localhost', $username, $password);
$db = mysql_select_db($database, $link);

@$inst = $_POST['inst'];

if($inst) {
///////////////////////////////////////////////////////////////////////////
$query = sprintf("SELECT * FROM instituition");
$result = @mysql_query($query);
$row = mysql_fetch_array($result);
///////////////////////////////////////////////////////////////////////////
}

?>

<html>
<head>
<title>:: Welcome to Student Services System ::</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script language="javascript" type="text/javascript">

function goto() {

var win = document.getElementById('inst').value; /// << added .value
document.location.href=win; /// <<< using .value

}

</script>
</head>
<body>

<form name="form1" method="post" action="newpage.php">
<select name="inst">
<option value="" selected>Select Instituition</option>
<?php do { ?>
<option value="<?php echo @$row['Inst_Id']; ?>"><?php echo @$row['InstName']; ?></option>
<?php } while ($row = mysql_fetch_array($result)); ?>
</select>
<input name="Go" type="button" id="Go" value="Go" onClick="goto()">
</form>

</body>
</html>