Simple form validation

前端 未结 4 452
北海茫月
北海茫月 2021-01-25 06:32

POST #1

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

                

Please select your Gift Certificate amount below

相关标签:
4条回答
  • 2021-01-25 06:54

    Give your form a name (GiftForm)

        <script type="text/javascript">
        function validate_form ( )
        {
            valid = true;
    
            if ( document.GiftForm.os1.value == "" )
            {
                alert ( "Please fill in the 'Your Name' box." );
                valid = false;
            }
    
            return valid;
        }
    </script>
    
    0 讨论(0)
  • 2021-01-25 06:59

    A couple of hints that should get you going.

    Add a submit event handler:

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

    Give IDs to the input fields you want to get.

    <input id="currency_code" type="hidden" name="currency_code" value="CAD">
    

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

    <script type="text/javascript">
    
        function validate() {
    
            var currencyCode = document.getElementById("currency_code");
    
            var ok = currencyCode.value !== '';
    
            return ok;
    
        }
    
    </script>
    
    0 讨论(0)
  • 2021-01-25 07:05

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

    0 讨论(0)
  • 2021-01-25 07:07

    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/

    0 讨论(0)
提交回复
热议问题