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.
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;
});
});







