/    Sign up×
Community /Pin to ProfileBookmark

How to check for textfields duplicates ?

Hi,

I am displaying data dynamically from a database the user has to put numbers in the textfields from 1 to N (it’s like a survey or vote) :

textfield1 — caseId — title
textfield2 — caseId — title
textfield3 — caseId — title
……

textfieldN — caseId — title

I want to validate :
1)a number can not duplicated, for example the user cannot input :
textfield1 = 2
textfield2 = 2

I need a javascript that prevent the user from entering duplicated numbers.

thanks your help is appreciated.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@vwphillipsOct 03.2007 — [CODE]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>
<script language="JavaScript" type="text/javascript">
/*<![CDATA[*/

function zxcNoDuplicates(zxcfrm,zxcclass){
zxcfrm=document[zxcfrm];
zxcfrm[zxcclass]=[];
var zxceles=zxcfrm.elements;
for (var zxc0=0;zxc0<zxceles.length;zxc0++){
if (zxceles[zxc0].className&&zxceles[zxc0].className.match(zxcclass)){
zxcfrm[zxcclass].push(zxceles[zxc0]);
zxceles[zxc0].ary=zxcfrm[zxcclass];
zxceles[zxc0].onkeyup=function(){ this.value=this.value.replace(/D/g,''); }
zxceles[zxc0].onblur=function(){ zxcCkDuplicates(this); }
}
}
}

function zxcCkDuplicates(zxcobj){
for (var zxc0=0;zxc0<zxcobj.ary.length;zxc0++){
if (zxcobj.ary[zxc0]!=zxcobj&&zxcobj.ary[zxc0].value.length>0&&zxcobj.ary[zxc0].value==zxcobj.value){
alert('No Duplicates Allowed');
zxcobj.focus();
return false;
}
}
return true
}



/*]]>*/
</script></head>

<body onload="zxcNoDuplicates('tst','noduplicates1');zxcNoDuplicates('tst','noduplicates2');">
<form name="tst" >
group 1<br />
<input class="realclass noduplicates1" type="text" />
<input class="realclass noduplicates1" type="text" />
<input class="realclass noduplicates1" type="text" />
<input class="realclass noduplicates1" type="text" />
<input class="realclass noduplicates1" type="text" />
<br />
Group 2
<br />
<input class="realclass noduplicates2" type="text" />
<input class="realclass noduplicates2" type="text" />
<input class="realclass noduplicates2" type="text" />

</form>
</body>

</html>[/CODE]
Copy linkTweet thisAlerts:
@mlotfiauthorOct 03.2007 — Thank you very much, I appreciate your help.

thanks lot.
×

Success!

Help @mlotfi 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.8,
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,
)...