Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jan 2009
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    onchange select box issues

    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.

    Code:
    <!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>

  • #2
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    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.
      Code:
      switchDiv(This.value);'>
    • Remove the javascript pseudo-protocol here:
      Code:
      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.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • #3
    New to the CF scene
    Join Date
    Jan 2009
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks so much. It works now!


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •