NameSilo

Prototype JS

SpaceshipSpaceship
NamecheapNamecheap
Namecheap AuctionsNamecheap Auctions
Watch

Eric

VIP Member
Impact
328
Ok, I'm not too well versed in JavaScript, but I can work with it. I recently downloaded Prototype/Scriptalicious. I'm slowly trying to replace certain parts of a site with the prototype.

I was wondering if any of you more experienced folks could tell me if something like this would work? Or, maybe if you have a better way of doing it.

It's basically waiting for the form to be submitted, then it will check the form fields.

Code:
Event.observe(window, 'load', function()
{
	$('form').observe('submit', function()
	{
		// Check Name
		if ($('sender_name').value == '' || $('sender_name').value == null)
		{
			error_msg += "\n Please enter your name";
		}

		// Check email
		if ($('sender_email').value == '' || $('sender_email').value == null)
		{
			error_msg += '\n Please enter a valid email address';
		}

		// Check Message
		if ($('sender_subject').value == '' || $('sender_subject').value == null)
		{
			error_msg += "\n Please choose a subject";
		}

		// Check Message
		if ($('sender_message').value == '' || $('sender_message').value == null)
		{
			error_msg += "\n Please enter a message";
		}

		// Check CAPTCHA
		if ($('captcha').value.search(/^[a-z0-9]{5}$/i) == -1)
		{
			error_msg += "\n Please enter the CAPTCHA code";
		}

		if (error_msg != "The following errors occurred:\n")
		{
			window.alert(error_msg);
			return false;
		}
		return true;
	});
});
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
0
Close
DomainEasy: white label portfolios are live. Enable yours.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Search: choose where to search from the All tab
Open the search at the top of any page. On the All tab, the list next to the search box lets you choose where to search: everything, all...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back