...

View Full Version : onchange select box issues



PocketAces
01-29-2009, 10:55 PM
I have managed to get this far (see code), but for some reason can not get it to work. I want to display the DIV of the same name as the select option when it is selected. (for simplicity sake, I have omitted most of the DIVs and included only 1 since they are almost identical.)

I'm not sure if its something simple or not, but any help would be greatly appreciated. And I know that there are many other questions like this out there, but when i adapted them to my code I couldn't get any of them to work. And alas, here I am.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="en" />
<meta name="GENERATOR" content="PHPEclipse 1.2.0" />
<title>24-7 Sign Up Page</title>

<script type="text/javascript">

function switchDiv(div_id)
{

var style_sheet = getStyleObject(div_id);
if (style_sheet)
{
hideAll();
changeObjectdisplay(div_id, "block");
}
else
{
alert("sorry, this only works in browsers that do Dynamic HTML");
}
}
function changeObjectdisplay(objectId, newdisplay) {
document.getElementById(objectId).style.display = newdisplay;
}
function hideAll()
{
changeObjectdisplay("mon","none");
changeObjectdisplay("tues","none");
changeObjectdisplay("wed","none");
changeObjectdisplay("thurs","none");
changeObjectdisplay("fri","none");
changeObjectdisplay("sat","none");
changeObjectdisplay("sun","none");
}

</script>
</head>
<body>

<?php

$con = mysql_connect("********","********","********");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("************", $con);

$result = mysql_query("SELECT * FROM Schedule");
if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;
}


?>

<h1 style='text-align:center'>24-7 2009 Sign Up</h1>

<table border='0' width='100%' cellpadding='10'>

<tr>

<td width='25%' valign='top' style='background-color:black;color:white'>
<p>24/7 2009 Home</p>
<p>The Current Calendar</p>
<p>Sign Up</p>
<p>About Us</p>
<p>100 Days Overview</p>
<p>90 Days of Blessing</p>
<p>The Global Day of Prayer</p>
</td>


<td width='75%' valign='top'>
<form action='FormHandler.php' method='post' name='SU'>
<p>*First Name: <input type='text' name='first'></p>
<p>*Last Name: <input type='text' name='last'></p>
<p>*Email: <input type='text' name='email' size='40'></p>
<hr />

<table>

<td>
<p><select name='day' onchange='Javascript:switchDiv(This.value);'>
<option>--Select a Day--</option>
<option value='mon'>Monday</option>
<option value='tues'>Tuesday</option>
<option value='wed'>Wednesday</option>
<option value='thurs'>Thursday</option>
<option value='fri'>Friday</option>
<option value='sat'>Saturday</option>
<option value='sun'>Sunday</option>
</select>
</td></p>



<?php

mysql_select_db("my_db", $con);

$result = mysql_query("SELECT * FROM Schedule");
if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;
}
$i=0;

$TimeRange = array("8am-9am","9am-10am","10am-11am","11am-12pm","12pm-1pm","1pm-2pm","2pm-3pm","3pm-4pm","4pm-5pm","5pm-6pm","6pm-7pm","7pm-8pm","8pm-9pm");
?>
<td>



<div id='tues' style='background-color:blue;display:none;'>
<table>
<td>
<?php
$Day='tues';
$i=0;
while($row[$i]=mysql_fetch_array($result)){
$i++;
}
$i=0;
while($i<6){
if ($row[$i][$Day]!=$TimeRange[$i])
echo "<p>Hour Covered</p>";
else
echo "<p>$TimeRange[$i]</p>";
$i++;
}
echo "</td>";
echo "<td>";
$i=0;
while($i<6){
if ($row[$i][$Day]!=$TimeRange[$i])
echo "<p><input type='checkbox' name='time' value=" . $TimeRange[$i] . " DISABLED></p>";
else
echo "<p><input type='checkbox' name='time' value=" . $TimeRange[$i] . "></p>";
$i++;
}
echo "</td>";
echo "<td>";
while($i<13){
if ($row[$i][$Day]!=$TimeRange[$i])
echo "<p>Hour Filled</p>";
else
echo "<p>$TimeRange[$i]</p>";
$i++;
}
echo "</td>";
echo "<td>";
$i=6;
while($i<13){
if ($row[$i][$Day]!=$TimeRange[$i])
echo "<p> </p>";
else
echo "<p><input type='checkbox' name='time' value=" . $ChxValue[$i] . "></p>";
$i++;
}

echo "</td></table>";

?>
</div>

rangana
01-30-2009, 06:13 AM
You might find these notes useful:


JS is case-sensitive. Uppercase and lowercase character makes difference.
With that said, this should be written in (all) lowercase characters.


switchDiv(This.value);'>



Remove the javascript pseudo-protocol here:


onchange='javascript:


It does nothing, rather than to cause your page to fail validation.


Hope that helps. Can't test any further as getStyleObject and changeObjectdisplay functions are both missing.

PocketAces
01-30-2009, 09:49 PM
Thanks so much. It works now!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum