/    Sign up×
Community /Pin to ProfileBookmark

Validate field onBlur using array

I was wondering how I could add a validate function to this script so that onBlur it checks the form field against the same array (on top)?

Any suggestions? I am new to JS and am struggling.

Here is the .js file.

[CODE]

var aName = new Array(

“Kafui Akondo”,
“Francesca Alesandrini”,
“Sanjana Anand”,
“Robyn Anden”,
“Arletta Anderson”,
“Choo Lian Mavis Ang”,
“Joanne Angell”,
“Christine Antonetti”,
“Ikuko Asakawa”,
“Michael Asercion”,
“Teresa Atchley-Legette”,
“Kacey Aumack”,
“Thomas Aurelio”,
“Alexander Austin”,

);

aName.sort();

function Complete(obj, evt) {
if ((!obj) || (!evt) || (aName.length == 0)) {
return;
}

if (obj.value.length == 0) {
return;
}

var elm = (obj.setSelectionRange) ? evt.which : evt.keyCode;

if ((elm < 32) || (elm >= 33 && elm <= 46) || (elm >= 112 && elm <= 123)) {
return;
}

var txt = obj.value.replace(/;/gi, “,”);
elm = txt.split(“,”);
txt = elm.pop();
txt = txt.replace(/^s*/, “”);

if (txt.length == 0) {
return;
}

if (obj.createTextRange) {
var rng = document.selection.createRange();
if (rng.parentElement() == obj) {
elm = rng.text;
var ini = obj.value.lastIndexOf(elm);
}
} else if (obj.setSelectionRange) {
var ini = obj.selectionStart;
}

for (var i = 0; i < aName.length; i++) {
elm = aName[i].toString();
if (elm.toLowerCase().indexOf(txt.toLowerCase()) == 0) {
obj.value += elm.substring(txt.length, elm.length);
break;
}
}

if (obj.createTextRange) {
rng = obj.createTextRange();
rng.moveStart(“character”, ini);
rng.moveEnd(“character”, obj.value.length);
rng.select();
} else if (obj.setSelectionRange) {
obj.setSelectionRange(ini, obj.value.length);
}
}

[/CODE]

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @ShaneSwodiddy 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.18,
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,
)...