Author Topic: javascript inquery (can't get show/hide to work properly :/)  (Read 2645 times)

Offline CK9

  • Administrator
  • Hero Member
  • *****
  • Posts: 6226
    • http://www.outpost2.net/~ck9
javascript inquery (can't get show/hide to work properly :/)
« on: February 06, 2014, 05:47:44 PM »
At the community I play minecraft with, we started playing Mafia on the forum.  For my turn to be the 'host' I decided to try to automate the round with PHP choosing who is what role and such so that I could add in a special role (played by myself) without the chance of creating a bias by knowing all the information.

For one of the pages, I wanted to have a form for a person to move to a new location with the information about the location displayed when they have it selected.  Basically, they change the selection from a to b, the info block for a hides and the info block for b shows.  From what (little) I know of javascript, the function *should* be working...but it never displays anything.

In case anyone here can help me, here's what I have (browser-side view source):

Code: [Select]
<html>
<head>

  <!--create dynamic form functions-->

  <script type="text/javascript">
  <!--

    function checkMovement(selectedType)
    {
      //displays or hides the information blocks for the methods of movement
      switch (selectedType)
      {
        case 'land':
        document.getElementById('land').style.display='block';
        document.getElementById('nether').style.display='none';
        document.getElementById('cave').style.display='none';
        document.getElementById('sign').style.display='none';
        break;
        case 'nether':
        document.getElementById('land').style.display='none';
        document.getElementById('nether').style.display='block';
        document.getElementById('cave').style.display='none';
        document.getElementById('sign').style.display='none';
        break;
        case 'cave':
        document.getElementById('land').style.display='none';
        document.getElementById('nether').style.display='none';
        document.getElementById('cave').style.display='block';
        document.getElementById('sign').style.display='none';
        break;
        case 'sign':
        document.getElementById('land').style.display='none';
        document.getElementById('nether').style.display='none';
        document.getElementById('cave').style.display='none';
        document.getElementById('sign').style.display='block';
        break;
      }
    }

    function showLocation(selectedLocation)
    {
      //displays or hides the information blocks for locations
      switch (selectedLocation)
      {
        case 'fortuna':
        document.getElementById('fortuna').style.display='block';
        document.getElementById('x').style.display='none';
        document.getElementById('m').style.display='none';
        document.getElementById('china').style.display='none';
        document.getElementById('fairville').style.display='none';
        document.getElementById('ffa').style.display='none';
        break;
        case 'x':
        document.getElementById('fortuna').style.display='none';
        document.getElementById('x').style.display='block';
        document.getElementById('m').style.display='none';
        document.getElementById('china').style.display='none';
        document.getElementById('fairville').style.display='none';
        document.getElementById('ffa').style.display='none';
        braek;
        case 'm':
        document.getElementById('fortuna').style.display='none';
        document.getElementById('x').style.display='none';
        document.getElementById('m').style.display='block';
        document.getElementById('china').style.display='none';
        document.getElementById('fairville').style.display='none';
        document.getElementById('ffa').style.display='none';
        break;
        case 'china':
        document.getElementById('fortuna').style.display='none';
        document.getElementById('x').style.display='none';
        document.getElementById('m').style.display='none';
        document.getElementById('china').style.display='block';
        document.getElementById('fairville').style.display='none';
        document.getElementById('ffa').style.display='none';
        break;
        case 'fairville':
        document.getElementById('fortuna').style.display='none';
        document.getElementById('x').style.display='none';
        document.getElementById('m').style.display='none';
        document.getElementById('china').style.display='none';
        document.getElementById('fairville').style.display='block';
        document.getElementById('ffa').style.display='none';
        break;
        case 'ffa':
        document.getElementById('fortuna').style.display='none';
        document.getElementById('x').style.display='none';
        document.getElementById('m').style.display='none';
        document.getElementById('china').style.display='none';
        document.getElementById('fairville').style.display='none';
        document.getElementById('ffa').style.display='block';
        break;
      }
    }

  //-->
  </script>

</head>
<body>

Welcome srentiln!<br>
<br>
You can use these links to check on things or perform actions.<br>
<table width='90%' alignment='center'>
<tr>
<td width='20%'><center><a href='gui.php?pg=inv'>Inventory/Eat</a></center></td>
<td width='20%'><center><a href='gui.php?pg=att'>Attack</a></center></td>
<td width='20%'><center><a href='gui.php?pg=mov'>Travel</a></center></td>
<td width='20%'><center><a href='gui.php?pg=wait'>Wait</a></center></td>
<td width='20%'><center><a href='gui.php?pg=spec'>Use Special</a></center></td>
</tr></table>
<table width='100%' height='1'><tr><td></td></tr></table>
<table width='100%'>
<tr>
<td>


<center> You are currently in x.  Please select your destination and method of travel.</center>
<table width='100%'><tr><td width='50%'><form action='action.php' method='post'>Move to: <select name="move" onChange=checkLocation(this)">
<option value='1'>fortuna</option>
<option value='3'>m</option>
<option value='4'>chinatown</option>
<option value='5'>fairville</option>
<option value='6'>ffa airship</option>
</select>  Via: <select name="method" onChange="checkMovement(this)">\n<option value="land">Surface</option>\n<option value="nether">Subway Tunnels</option>\n<option value="cave">Mine Tunnels</option>\n<option value="sign">Checkpoint signs</option>\n</select>  <input type="submit"></form></td><td width='50%'>
<div id="fortuna" style="display:none;">City information:<br> Once a prosperous desert town of trade, changes in plugins and recent events have left Fortuna nearly abandond.  The city has no protection against mob invasion, but it is the only location where the mysterious merchant sells potions.</div>
<div id="x" style="display:none;">City information:<br> The original &quot;Spawn Town&quot; of zero, X has many places to hide and many treasures that one might find.  The accumulation of torches and large amount of water makes mob attack less likely than many other locations.  Chances of spotting other players is reduced.</div>
<div id="m" style="display:none;">City information:<br> High above the land, M is free of mobs.  However, it is also lacking in places to hide and places to stand.  Visitors could find themselves in X while wandering around.</div>
<div id="china" style="display:none;">City information: encompassed by a curtain wall and filled with the random buildings of green hopefulls, China still has a few secrets to uncover.  Mobs are a constant threat here.</div>
<div id="fairville" style="display:none;">City information: originally intended as a replacement for X, Fairville stands fairly empty.  The open plots that wait for eager builders are a mix of light and dark.  Those who explore the area might find some food.</div>
<div id="ffa" style="display:none;">Location information: The stationary airship that once provided links to all the mazes now serves as a haven with random paths out.  No mobs can spawn here, and a few pieces of food can be found here.  However, you must risk a random teleportation to find it, not to mention the lava pool below.</div>
<br><br>
<div id="land" style="display:none;">Method information: Traveling on the surface of zero comes with risk from mobs and the occasional hole, but it is unlikely that you will find another person along the way.  If you get lost, you might end up somewhere other than you intended</div><div id="nether" style="display:none;">Method information: Taking the subway tunnels prevents you from beling lost, but it is much harder to hide from other people.  Occasionally, you might find lava leaking down on top of you.  Watch out for the zombie pigmen, and you should be fine, right?</div>
<div id="cave" style="display:none;">Method information: over its three years, zero has seen a lot of mining in its underground.  This has lead to vast distances being connected underground.  It is unlikely you'll run into other players inside the maze of caverns, but keeping on course is another matter...not to mention the occasional dungeon.</div>
<div id="sign" style="display:none;">Method information: While the checkpoint signs were once one of the most reliable methods of getting around, the corruption that engulfed the server had some lasting effects on the signs.  Sure, you won't have to worry about mobs or players, but you never know if you are going to end up where you wanted to be...</div>
</td></tr></table>
</td>
</tr>
</table>
</body>
</html>

Nothing ever displays.  I am fairly certain it can't be the php end breaking it, because I did the background research before hand to make sure the two would play nice together.
CK9 in outpost
Iamck in runescape (yes, I still play...sometimes...)
srentiln in minecraft (I like legos, and I like computer games...it was only a matter of time...) and youtube...
xdarkinsidex on deviantart

yup, I have too many screen names