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

The function isn’t properly closed, put a } on line 80 :slight_smile:


function CheckFrm2()
{
	alert("Hello World 2");

	var error_message="";
	var data = document.signup;

	if(!checkInput(data.username.value)) { error_message = " - Missing nick name\
"; }
	if(!checkInput(data.email.value)) { error_message = error_message + " - Missing email\
"; }
	if(!checkInput(data.pswd.value)) { error_message = error_message + " - Missing password\
"; }
	if(!checkInput(data.mygender.value)) { error_message = error_message + " - Missing selection for your gender \
"; }
	if(!checkInput(data.lookgender.value)) { error_message = error_message + " - Missing selection for what gender you seek\
"; }
	if(data.age.value == 0) { error_message = error_message + " - Missing selection for your Age\
"; }
	if(data.country.value == 0) { error_message = error_message + " - Missing Country selection\
"; }

	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\
"; }

		if(error_message != ""){
			alert("Please check these fields:\
\
"+error_message);
			return false;
		}

		return true;
	}
}

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,

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.

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.

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

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!

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 :slight_smile: