Hi, i’m new in javascript so i think i could use some gelp on this one. I have a form, and i want to use onBlur() on some text fields for validation. I found out that i can’t have it return two different functions, and although i tried i just can’t make a function, containing the two i want to use, work.
So, i want a function called checkCardNum containing these two:
<script language=”javascript”>
function checkNumbers(string, ignoreWhiteSpace) {
if (string.search) {
if ((ignoreWhiteSpace && string.search(/[^ds]/) != -1) || (!ignoreWhiteSpace && string.search(/D/) != -1))
{alert(“Please check you have entered only numbers”)
return false;
}
}
return true;
}
</script>
<script language=”javascript”>
function checkCreditCard(number) {
var number = ” + number;
if (number.length > 16 || number.length < 13 )
{ alert(“Credit card number must have 13 to 16 digits”)
return false; }
else return true;
}
</script>
and another one called checkCodeNum containing these two:
<script language=”javascript”>
function checkCode(number) {
var number = ” + number;
if (number.length > 4 || number.length < 3 )
{ alert(“Security code must have 3 to 4 digits”)
return false; }
else return true;
}
</script>
<script language=”javascript”>
function checkNumbers(string, ignoreWhiteSpace) {
if (string.search) {
if ((ignoreWhiteSpace && string.search(/[^ds]/) != -1) || (!ignoreWhiteSpace && string.search(/D/) != -1))
{alert(“Please check you have entered only numbers”)
return false;
}
}
return true;
}
</script>
Last but not least, i have another function, again for validating purposes, which works for the text fileds but not for the select menu. so my guess is i don’t use selectedIndex correctly.
Here’s some piece of the code:
function checkForm( theform )
{
var bMissingFields = false;
var strFields = “”;
if( theform.bill_name.value == ” ){
bMissingFields = true;
strFields += ” Billing: Namen”;
}
if( theform.bill_country.selectedIndex == ‘Country’ ){
bMissingFields = true;
strFields += ” Billing: Countryn”;
}
i want bMissing fields to return true if the option selected in the bill_country is country
thanks,
Anthi