...

View Full Version : Resolved JS in PHP



myfayt
12-07-2010, 03:59 PM
I had posted this in the JS forum, but was told they couldn't help me because it has to do with PHP.

I am trying to get a show/hide feature working, when they select an option from the select box. The first select box works perfectly.

However the second one with (set entry, question, highest level) etc doesn't work at all, nothing happens.


JS Header

<script type="text/javascript">

function ShowReg(op) {
document.getElementById('public').style.display='none';
document.getElementById('alliance').style.display='none';

switch (op) {
case 1 : document.getElementById('public').style.display="block"; break;
case 2 : document.getElementById('alliance').style.display="block"; break;

default : break;
}
}

function ShowNext(op) {
document.getElementById('randomwin').style.display='none';
document.getElementById('setentry').style.display='none';
document.getElementById('highestlevel').style.display='none';
document.getElementById('question').style.display='none';


switch (op) {
case 1 : document.getElementById('randomwin').style.display="block"; break;
case 2 : document.getElementById('setentry').style.display="block"; break;
case 3 : document.getElementById('highestlevel').style.display="block"; break;
case 4 : document.getElementById('question').style.display="block"; break;


default : break;
}
}
</script>


$page .= '<tr><td><b>Privacy:</b></td><td>
<select name="privacy" id="choice" onChange="ShowReg(this.selectedIndex)">
<option value="error">Select One</option>
<option value="public">Public</option>
<option value="alliance">Alliance Only</option>
</select>
</td></tr></table><br />';
$page .= '<div id="public" style="display:none">
<p><b>Contest will be made Public for all players to use.</b>
</div>
<div id="alliance" style="display:none">
<p><b>Contest will be made available to only alliance members.</b>
</div>';

//Random Draw = Select a random winner
//Marked Entry = Select an entry number, and when that number comes up, announce winner. I.E. 12, 11th entry bypassed, 12th entry wins.
//Highest Level = Whoever is the highest level with an entry wins.
//Answer Question = Creator posts a question and submits the answer. Players must guess the correct answer from a list of answers.
$page .= '<table width="50%">';
$page .= '<tr><td><b>Type:</b></td><td>
<select name="contype" id="second" onChange="ShowNext(this.selectedIndex)">
<option value="error">Select One</option>
<option value="randomwin">Random Draw</option>
<option value="setentry">Marked Entry</option>
<option value="highestlevel">Highest Level</option>
<option value="question">Answer Question</option>
</select></td></tr></table><br />';

$page .= '<div id="randomwin" style="display:none">
<p>Random draw selected
</div>';
$page .= '
<div id="winner" style="display:none">
<p>Select Entry number to auto win:
<select name="entrypick">
<option value="5">Entry 5</option>
<option value="6">Entry 6</option>
<option value="7">Entry 7</option>
<option value="8">Entry 8</option>
<option value="9">Entry 9</option>
<option value="10">Entry 10</option>
<option value="11">Entry 11</option>
<option value="12">Entry 12</option>
<option value="13">Entry 13</option>
<option value="14">Entry 14</option>
<option value="15">Entry 15</option>
<option value="16">Entry 16</option>
<option value="17">Entry 17</option>
<option value="18">Entry 18</option>
<option value="19">Entry 19</option>
<option value="20">Entry 20</option>
<option value="21">Entry 21</option>
<option value="22">Entry 22</option>
<option value="23">Entry 23</option>
<option value="24">Entry 24</option>
<option value="25">Entry 25</option>
<option value="26">Entry 26</option>
<option value="27">Entry 27</option>
<option value="28">Entry 28</option>
<option value="29">Entry 29</option>
<option value="30">Entry 30</option>
</select>
</div>

<div id="highestlevel" style="display:none">
<p>You selected highest level. Whoever enters with highest level at time of entry wins!
</div>

<div id="question" style="display:none">
<p>Type the question and all answers. If more than one person is correct, prize is split.<br />
<b>Question:</b> <input type="text" name="question" value=""><br />
<b>Answer 1:</b> <input type="text" name="answer1" value=""><br />
<b>Answer 2:</b> <input type="text" name="answer2" value=""><br />
<b>Answer 3:</b> <input type="text" name="answer3" value=""><br />
<b>Answer 4:</b> <input type="text" name="answer4" value=""><br />
<b>Answer 5:</b> <input type="text" name="answer5" value=""><br />
<b>Answer 6:</b> <input type="text" name="answer6" value=""><br />
<b>Answer 7:</b> <input type="text" name="answer7" value=""><br />
<b>Answer 8:</b> <input type="text" name="answer8" value=""><br />
</div>';

poyzn
12-07-2010, 04:08 PM
you have two elements with the same id = choice. First of all make them different.

myfayt
12-07-2010, 04:39 PM
Ok changed it, still nothing. Here is what the error console shows in Firefox.


Error: document.getElementById("setentry") is null
Source File: http://www.rodgame.org/contest.php?x=create
Line: 74

poyzn
12-07-2010, 04:51 PM
Ok changed it, still nothing. Here is what the error console shows in Firefox.

I don't see any select boxes on that page

UPD: oh, sorry. I have to login to see the page but I don't want to register.
Could you make another page with the same functionality but without authorizing?

myfayt
12-07-2010, 06:53 PM
You can use the test account.

User: Test
Pass: Test

Soon as you login, do the following steps to get to the page.

1. Click (Enter) to go to the game

2. Click (Go to Town) on right side of picture

3. Click (Contests) found right in the middle of the links.

Then create contest and that is the page with the problems. You will notice public/alliance works fine.

myfayt
12-07-2010, 06:55 PM
You can use the test account.

User: Test
Pass: Test

Soon as you login, do the following steps to get to the page.

1. Click (Enter) to go to the game

2. Click (Go to Town) on right side of picture

3. Click (Contests) found right in the middle of the links.

Then create contest and that is the page with the problems. You will notice public

poyzn
12-08-2010, 06:00 AM
Checked. Try to add an element with id = setentry on the page

myfayt
12-08-2010, 01:27 PM
What type of element? there is lots of kinds.

poyzn
12-08-2010, 02:11 PM
What type of element? there is lots of kinds.
there is no elements with id="setentry" on the page you've showed me. So you're trying to hide it and javascript can't find it and shows you the error. add some <div id="setentry">some content to show</div>

myfayt
12-08-2010, 05:50 PM
Awesome that worked, now everything is good. Changed id="winner" to id="setentry" and it caused everything to work. Thank you! :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum