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 10 of 10

Thread: JS in PHP

  1. #1
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,470
    Thanks
    71
    Thanked 104 Times in 103 Posts

    JS in PHP

    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
    PHP Code:
    <script type="text/javascript">

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

      switch (
    op) {
        case 
    document.getElementById('public').style.display="block"; break;
        case 
    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 
    document.getElementById('randomwin').style.display="block"; break;
        case 
    document.getElementById('setentry').style.display="block"; break;
        case 
    document.getElementById('highestlevel').style.display="block"; break;
        case 
    document.getElementById('question').style.display="block"; break;


        default : break;
      }
    }
    </script> 
    PHP Code:
    $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>'

    Last edited by myfayt; 12-08-2010 at 05:53 PM. Reason: Updated code

  • #2
    Regular Coder poyzn's Avatar
    Join Date
    Nov 2010
    Posts
    266
    Thanks
    2
    Thanked 61 Times in 61 Posts
    you have two elements with the same id = choice. First of all make them different.

  • #3
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,470
    Thanks
    71
    Thanked 104 Times in 103 Posts
    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

  • #4
    Regular Coder poyzn's Avatar
    Join Date
    Nov 2010
    Posts
    266
    Thanks
    2
    Thanked 61 Times in 61 Posts
    Quote Originally Posted by myfayt View Post
    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?
    Last edited by poyzn; 12-07-2010 at 04:57 PM.

  • #5
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,470
    Thanks
    71
    Thanked 104 Times in 103 Posts
    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.

  • #6
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,470
    Thanks
    71
    Thanked 104 Times in 103 Posts
    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

  • #7
    Regular Coder poyzn's Avatar
    Join Date
    Nov 2010
    Posts
    266
    Thanks
    2
    Thanked 61 Times in 61 Posts
    Checked. Try to add an element with id = setentry on the page

  • #8
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,470
    Thanks
    71
    Thanked 104 Times in 103 Posts
    What type of element? there is lots of kinds.

  • #9
    Regular Coder poyzn's Avatar
    Join Date
    Nov 2010
    Posts
    266
    Thanks
    2
    Thanked 61 Times in 61 Posts
    Quote Originally Posted by myfayt View Post
    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>

  • Users who have thanked poyzn for this post:

    myfayt (12-08-2010)

  • #10
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,470
    Thanks
    71
    Thanked 104 Times in 103 Posts
    Awesome that worked, now everything is good. Changed id="winner" to id="setentry" and it caused everything to work. Thank you!


  •  

    Posting Permissions

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