Skip to content Skip to sidebar Skip to footer

Simple Form Validation

POST #1 How can I validate this simple form (checking for empty field strings)?

Please select your Gift Certificate amount below. Please also enter your na

Solution 1:

Is jQuery an option? There's a really nice Validation tool http://docs.jquery.com/Plugins/Validation

Solution 2:

A couple of hints that should get you going.

Add a submit event handler:

<formaction="https://www.paypal.com/cgi-bin/webscr"method="post"onsubmit="return validate()">

Give IDs to the input fields you want to get.

<inputid="currency_code"type="hidden" name="currency_code" value="CAD">

Write the validation code, return false if you don't want to submit.

<scripttype="text/javascript">functionvalidate() {

        var currencyCode = document.getElementById("currency_code");

        var ok = currencyCode.value !== '';

        return ok;

    }

</script>

Solution 3:

Give your form a name (GiftForm)

<scripttype="text/javascript">functionvalidate_form ( )
    {
        valid = true;

        if ( document.GiftForm.os1.value == "" )
        {
            alert ( "Please fill in the 'Your Name' box." );
            valid = false;
        }

        return valid;
    }
</script>

Solution 4:

Here is a simple tutorial along with demo and source code, I hope this works for you, all the best! http://gonga.in/simple-javascript-form-validation/

Post a Comment for "Simple Form Validation"