www.webdeveloper.com
Results 1 to 4 of 4

Thread: [UNDEFINED ERROR] Please help :)

Hybrid View

  1. #1
    Join Date
    Jul 2009
    Posts
    2

    Angry [UNDEFINED ERROR] Please help :)

    Hello there, this is my first post here, and I've just started javascript. My problem is that I get an undefined error on this page after i write the result and click on the "Click Here to vote" button.

    Here's the page : http://85.204.99.55/top5/index.php?a=in&u=crimes

    (Hope this won't be considered advertising)


    My script source is :


    Code:
                
        <script type="text/javascript">
        var a = Math.ceil(Math.random() * 20);
        var b = Math.ceil(Math.random() * 20);       
        var c = a + b
        function DrawBotBoot()
        {
            document.write("What is "+ a + " + " + b +"? ");
            document.write("<input id='BotBootInput' type='text' maxlength='2' size='2'/>");
    
        }    
        function ValidBotBoot(){
            var d = document.getElementById('BotBootInput').value;
    		
            if (d == c){   
    		        window.location = "{$list_url}/index.php?a=in&amp;u={$username}&amp;sid={$sid}";
    				
         }
    	 else
            return false;
    		
            
        }
        </script>
    
        
        
        
    </head>
    <body>
    
    Are you human?<br />
    
    <script type="text/javascript">DrawBotBoot()</script>
    <input id="Button1" type="button" value="Click Here to Vote" onclick="alert(ValidBotBoot());"/>
    The original code :

    Code:
        <script type="text/javascript">
        var a = Math.ceil(Math.random() * 10);
        var b = Math.ceil(Math.random() * 10);       
        var c = a + b
        function DrawBotBoot()
        {
            document.write("What is "+ a + " + " + b +"? ");
            document.write("<input id='BotBootInput' type='text' maxlength='2' size='2'/>");
        }    
        function ValidBotBoot(){
            var d = document.getElementById('BotBootInput').value;
            if (d == c) return true;        
            return false;
            
        }
        </script>
    
        
        
        
    </head>
    <body>
    
    Are you human?<br />
    
    <script type="text/javascript">DrawBotBoot()</script>
    <input id="Button1" type="button" value="Check" onclick="alert(ValidBotBoot());"/>

    What am i missing? What did i do wrong?

    Thank you in advance and have a nice day !


  2. #2
    Join Date
    Jun 2008
    Posts
    62
    You don't have an undefined error, you're simply opening a message box with an undefined argument:

    Code:
    onclick="alert(ValidBotBoot());"
    If the user gives the right answer, ValidBotBoot() doesn't return anything, therefore the output is undefined. Return true in that case and/or add an if clause
    Code:
    onclick="if(ValidBotBoot()===false){alert('incorrect')};"
    if you don't want any popup on a correct input.
    Last edited by Malgrim; 07-04-2009 at 11:03 AM. Reason: typos ... as usual

  3. #3
    Join Date
    Jul 2009
    Posts
    2
    Appreciate your help. Thank you very much !

  4. #4
    Join Date
    Apr 2012
    Posts
    1

    Quick question

    Here is what i have modified, and its not working

    HTML Code:
    <script type="text/javascript">
        var a = Math.ceil(Math.random() * 20);
        var b = Math.ceil(Math.random() * 20);       
        var c = a + b
        function DrawBotBoot()
        {
            document.write("What is "+ a + " + " + b +"? ");
            document.write("<input id='BotBootInput' type='text' maxlength='2' size='2'/>");
        }    
        function ValidBotBoot(){
            var d = document.getElementById('BotBootInput').value;
            if (d == c) return true; 
            (alert("Wrong Code"));
            document.getElementById('tryagain').value();
            return 'Wrong Answer';    }
        </script>
    I am trying to Target a span ID, <span id="tryagain"></span>

    But I cannot get it to target, Any ideas?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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
  •  
HTML5 Development Center



Recent Articles