SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,033
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Javascript code is NOT firing! what is wrong?

    Hello,

    I am creating a new Web site and want the forms checked by Javascript before the data are submitted to the server.

    I am using the same Javascript code that I have used for this purpose, but for some strange reason the Javascript is NOT firing and instead the form is submitted to the server before client side Javascript checking is done.

    You can see the page under developmet here:
    dreamdates.com - TOTALLY FREE online dating service - date singles ready for romance and love

    For example click on "Sign Me Up" button without filling some form inputs, you should get Javascript alert messaage about forms that have not been filled yet, but that does not happen and instead the form is submitted to server!

    What is going on!

    Regards,
    Dean

    Anoox search engine volunteer

    www.anoox.com

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,031
    Mentioned
    152 Post(s)
    Tagged
    2 Thread(s)
    The function isn't properly closed, put a } on line 80

    Code javascript:
    function CheckFrm2()
    {
    	alert("Hello World 2");
     
    	var error_message="";
    	var data = document.signup;
     
    	if(!checkInput(data.username.value)) { error_message = " - Missing nick name\n"; }
    	if(!checkInput(data.email.value)) { error_message = error_message + " - Missing email\n"; }
    	if(!checkInput(data.pswd.value)) { error_message = error_message + " - Missing password\n"; }
    	if(!checkInput(data.mygender.value)) { error_message = error_message + " - Missing selection for your gender \n"; }
    	if(!checkInput(data.lookgender.value)) { error_message = error_message + " - Missing selection for what gender you seek\n"; }
    	if(data.age.value == 0) { error_message = error_message + " - Missing selection for your Age\n"; }
    	if(data.country.value == 0) { error_message = error_message + " - Missing Country selection\n"; }
     
    	if(checkInput(data.email.value) && checkInput(data.email2.value)) { 
    		if(data.email.value != data.email2.value) { error_message = error_message + " - Re-entered emails do not match\n"; }
     
    		if(error_message != ""){
    			alert("Please check these fields:\n\n"+error_message);
    			return false;
    		}
     
    		return true;
    	}
    }
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,033
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks for that tip.
    I cannot believe that I missed that!
    But that is what I hate about JS, that is one gets no Error message.
    OTN, is there a plug-in to one of the Web browsers now that would
    provide one with JS Error messages when the debug mode for JS is
    truned on? So as developed we could see any JS Error messages when
    we have this software (plug-in) On?

    Regards,

    Quote Originally Posted by ScallioXTX View Post
    The function isn't properly closed, put a } on line 80
    Code javascript:
    function CheckFrm2()
    {
    	alert("Hello World 2");
     
    	var error_message="";
    	var data = document.signup;
     
    	if(!checkInput(data.username.value)) { error_message = " - Missing nick name\n"; }
    	if(!checkInput(data.email.value)) { error_message = error_message + " - Missing email\n"; }
    	if(!checkInput(data.pswd.value)) { error_message = error_message + " - Missing password\n"; }
    	if(!checkInput(data.mygender.value)) { error_message = error_message + " - Missing selection for your gender \n"; }
    	if(!checkInput(data.lookgender.value)) { error_message = error_message + " - Missing selection for what gender you seek\n"; }
    	if(data.age.value == 0) { error_message = error_message + " - Missing selection for your Age\n"; }
    	if(data.country.value == 0) { error_message = error_message + " - Missing Country selection\n"; }
     
    	if(checkInput(data.email.value) && checkInput(data.email2.value)) { 
    		if(data.email.value != data.email2.value) { error_message = error_message + " - Re-entered emails do not match\n"; }
     
    		if(error_message != ""){
    			alert("Please check these fields:\n\n"+error_message);
    			return false;
    		}
     
    		return true;
    	}
    }

    Anoox search engine volunteer

    www.anoox.com

  4. #4
    SitePoint Enthusiast Anthony.Barnes's Avatar
    Join Date
    Aug 2011
    Location
    Canberra, Australia
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by WorldNews View Post
    But that is what I hate about JS, that is one gets no Error message.
    The web browser will generally give you good feedback on an error message, with the exception of IE which is known for obtuse js errors. Syntax errors like the one you had usually generate fairly obvious errors, but its up to the individual browser type to choose how to warn you.

    Quote Originally Posted by WorldNews View Post
    OTN, is there a plug-in to one of the Web browsers now that would
    provide one with JS Error messages when the debug mode for JS is
    truned on?
    I use a jslint plugin for my text editor which tells me about formatting/syntax issues before I deliver the code to the browser. You can also enable a javascript console on all modern browsers:

    Chrome (ctrl+shift+i or ctrl+shift+j)
    Firefox (install firebug addon, adds some nice stuff around the default FF console)
    IE 8 + (f12)
    Safari (Web developer tools in the preferences menu)

    I'm pretty sure opera has one as well - it seems to move around every version update - in 11.11 you can tell errors to open the js console automatically by using ctrl+f12 -> advanced -> content -> javascript options.

    Short story: almost every modern browser already has these tools available either by default on a vanilla installation or as an addon.

    Try out JSHint, A JavaScript Code Quality Tool as well if you want to run your code through validation before implement it.

  5. #5
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,031
    Mentioned
    152 Post(s)
    Tagged
    2 Thread(s)
    Yes, opera has DragonFly, also opens with ctrl + shift + i, like on chrome
    And you can open the one in chrome, and firebug on firefox, with f12 also
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  6. #6
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,033
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I created a simple Javascript Errors, that thus I would know of, and then tried the F12 function on chrome and it gives NO Error message about why the JS code is not firing properly!

    Or did I miss something in Chrome about this!



    Quote Originally Posted by ScallioXTX View Post
    Yes, opera has DragonFly, also opens with ctrl + shift + i, like on chrome
    And you can open the one in chrome, and firebug on firefox, with f12 also

    Anoox search engine volunteer

    www.anoox.com

  7. #7
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,031
    Mentioned
    152 Post(s)
    Tagged
    2 Thread(s)
    No chrome doesn't say that. I found the error when I copied you code, put it in netbeans, and said "Format code". That's when I saw (NetBeans doesn't give an error) that the curly brackets didn't match. Plus, NetBeans highlights the corresponding bracket when your cursor is on a bracket; also very handy
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy


Bookmarks

Posting Permissions

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