/    Sign up×
Community /Pin to ProfileBookmark

newbie help

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

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @Anthi spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...