javascript check function for a html form

Posted by Reteras Remus on Stack Overflow See other posts from Stack Overflow or by Reteras Remus
Published on 2012-07-08T08:44:58Z Indexed on 2012/07/08 9:15 UTC
Read the original article Hit count: 234

Filed under:
|
|
|
|

I'm having a problem with a HTML form (name, e-mail, subject, message), I can't validate the form if it was completed correct or not. I want to call a javascript function when the form is submitted and alert if a field wasn't completed correct.

My problem is with the submit button, because my boss said that I must use he's own php function to insert a submit button. The php function looke like:

function normal_button($text, $width, $param = '', $class = 'button-blue')
{
    $content = '<div class="'.$class.'" style="width:'.$width.'px;" '.$param.'>'.$text.'</div>';

    return $content;
}

and how I call the function:

echo normal_button('Send it', '100', 'onclick="document.getElementById(\'emailForm\').submit();" ');

I tried to call the js function declaring the onSubmit="return checkForm(this)" in the <form action='email.php' method='post'> HTML form, but I can't "catch" the submit. Also I tried to catch it with jquery, $(document).ready(function() { $('.normal_button').click(function() { }); ); but I can't return false if a field wasn't completed correct.

I must use he's PHP function to insert the submit button, but how can I "catch" the fields, how can I validate them? Any suggestions? Thank you !

© Stack Overflow or respective owner

Related posts about php

Related posts about jQuery