www.webdeveloper.com
Results 1 to 6 of 6

Thread: Where is "Wally"??

  1. #1
    Join Date
    Oct 2011
    Posts
    4

    Question Where is "Wally"??

    Hello,

    I'm looking for "Wally in this piece of code but just can't figure out why the javascript is always sending me the "GOOOOODDD" message even when I enter 'aaa' in the text box.
    From my perspective, when aaa is found, the BAAADDD!!! message should be issued and it's not.

    "Wally" is the error that I can't figure out.

    If someone could give me hint where this is going bad I'd really appreciate.

    Than You for your time

    ___________________________________________________________

    SOURCE CODE:
    HTML Code:
    <script language="javascript" type="text/javascript">
    <!--
    function GetAAA(that)  
    {  
     	var mytext=document.getElementById("BLABLA")  
     
     	if (mytext == "aaa")
     	 	
     		alert("BAAAAADDDDD!!!!" + mytext.value);
     	else
     		alert(" GOOOODDDD!!!!" + mytext.value);	
    }
    	-->  
    </script>  
    </head>
    
    <body>  
    	<form id="form1" method="get" onsubmit="getAAA(this)" />
    	<input 	name="BLABLA" 
    			size="3"  
    			type="text"/> Input Data 
    			
    		<br/><br/>
    			
    	<input name="Submit1" type="submit" value="submit" />
    	
    </body>
    </html>

  2. #2
    Join Date
    Jan 2007
    Location
    Wisconsin
    Posts
    2,120
    mytext is a node, not a string. Use:

    Code:
     	if (mytext.value == "aaa")
    ... also use http://w3schools.com/ ....
    Jon Wire

    thepointless.com | rounded corner generator

    I agree with Apple. Flash is just terrible.

    Use CODE tags!

  3. #3
    Join Date
    Jan 2009
    Location
    Insanity
    Posts
    1,131
    function GetAAA(that)

    <form id="form1" method="get" onsubmit="getAAA(this)" />

    Typos also bring down javascripts like a house of cards...

    I will also say that you want to chose a naming convention that is meaningful, "BLABLA" is not a meaningful variable, if you were to have called it UserResponse then you would know what data it may contain.
    Last edited by JunkMale; 10-19-2011 at 03:52 PM. Reason: Added stuff, Gahhhhh!

  4. #4
    Join Date
    Oct 2011
    Posts
    4
    Thanks for the reply svidgen,


    I changed it and now I get me this message:

    Uncaught exception: TypeError: Cannot convert 'mytext' to object
    Error thrown at line 7, column 2 in getAAA(that)
    if (mytext.value == "aaa")
    called from line 1, column 0 in <anonymous function>(event):
    getAAA(this)

    Is there a way to fix this?


    thanks

  5. #5
    Join Date
    Oct 2011
    Posts
    4
    Thanks for the reply, Junkmale,

    I agree with you regarding the convention, but this is just a test.

    In the real world, all have meaningful names.

    Anyway, thanks for the heads-up.

  6. #6
    Join Date
    Jan 2009
    Location
    Insanity
    Posts
    1,131
    I did a test of my own and found other issues like a missing </form tag and wrote the code below.

    Code:
    <script type="text/javascript">
    
    function GetAAA(that){  
    	
    mytext=that.BLABLA.value;  
    if( mytext == "aaa" ){
    	Disp = "Bad";
    	}else{
    		Disp = "Good";
    		}
    
    alert( Disp + " Choice " + mytext);
    return false;
    }
    	-->  
    </script>  
    </head>
    
    <body>  
    	<form id="form1" method="get" action="" onSubmit="return GetAAA(this);">
    	<input 	name="BLABLA"  type="text" value=""> Input Data <br><br>
    	<input name="Submit1" type="submit" value="submit">
    	</form>
    </body>
    </html>
    The idea is simple and you use the that variable that you pass on the submit of a form when the function is called. prefixing the return to it allows you to either allow the form to submit or to fail by returning true or false.

    Hope that helps you, I kept your naming convention so you can see how it works.

Thread Information

Users Browsing this Thread

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

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