a little problem with javascript

dragut

Junior Member
Jul 26, 2001
3
0
0
This script should print out all these first sentence words which are also in second sentence. It almost work, but I'd like to that, if there are such sentences:
1. ja ja ja ei ei
2. ja ei ei

and the pintout should be :

ja
ei

Now the printou is :

ja
ei
ei

How can do that if there 2 ei's in the first sentence, in the printout is only one?

The script itself is here:

<html>
<head>
<title>Kodune &uuml;lesanne</title>

<script>

function yhesugused_sonad() {

sonad=new Array();

var lause1=document.vorm1.tekst1.value;
var lause2=document.vorm1.tekst2.value;

lause1_mass=lause1.split(" ");
lause2_mass=lause2.split(" ");

var x=0;
var t=0;
sonad[x]="";
for (var i=0;i<lause1_mass.length;i++){
for (var a=0;a<lause2_mass.length;a++) {
if (lause1_mass==lause2_mass[a]) {
for (var x=0;x<sonad.length;x++) {
if (lause1_mass==sonad[x]) {
alert('olemas '+sonad[x]);
x=sonad.length;
} else {
x=t;
sonad[x]=lause1_mass;
t=t+1;
//x=sonad.length;
}
}
//sonad[x]=lause1_mass;
a=lause2_mass.length;
//x=x+1;

}
}
}
for (var x=0;x<sonad.length;x++) {
document.writeln(sonad[x]+'
')
}
}



</script>

</head>
<body>
<font face="Arial">
<b>This will find out these 1. sentence words which are also in the 2. sentence</b>
<form name="vorm1">
1. sentence: <input type="text" name="tekst1" size="100">


2. sentence: <input type="text" name="tekst2" size="100">


<input type="button" value="Otsi" onClick="yhesugused_sonad()">
</form>
</font>
</body></html>