POST #1
How can I validate this simple form (checking for empty field strings)?
Please select your Gift Certificate amount below
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>
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>
Is jQuery an option? There's a really nice Validation tool http://docs.jquery.com/Plugins/Validation
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/