Ich habe einen von mir geschriebenen Javascript Code und würde den gerne in einen Javacode umschreiben. Kann mir dabei jemand helfen?
Hier der Code:
Hier der Code:
HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>Text-Statistik</title>
<script type="text/javascript">
function auswerten()
{
var text = document.forms['f1'].textarea_in.value;
var wort_array = text.split(" ");
var new_text = new Array();
for (var i=0;i<wort_array.length;i++)
{
new_text[i]=normalisiertesWort(wort_array[i]);
}
document.forms['f1'].anzahl.value = i;
function normalisiertesWort(s)
{
var satzZeichen = "\",;:.!?-"; //herauszufilternde Zeichen
var w = "";
s = s.toLowerCase(); // Umwandlung in Kleinbuchstaben
for (var i=0; i < s.length; i++)
{
if (satzZeichen.indexOf( s.charAt(i)) == -1) // kein Satzzeichen
{
w = w + s.charAt(i); // also in den Wortstring uebernehmen
}
}
return w
}
new_text.sort();
var j=1;
array=new Array();
var m=0;
for(var k=0;k<new_text.length;k++)
{
if(new_text[k] === new_text[k+1])
{
j++;
}
else
{
array[m] = new Array(2);
array[m][0] = new_text[k];
array[m][1] = j;
m++;
j=1;
}
}
var tausch_a;
var tausch_b;
var unsortiert = true;
while(unsortiert)
{
unsortiert = false;
for(m=0; m<array.length-1 ;m++)
{
if(array[m][1] < array[m+1][1])
{
tausch_a = array[m+1][1];
tausch_b = array[m+1][0];
array[m+1][1] = array[m][1];
array[m+1][0] = array[m][0];
array[m][1] = tausch_a;
array[m][0] = tausch_b;
unsortiert = true;
}
}
}
document.forms['f1'].elements[4].value ="Wort";
document.forms['f1'].elements[5].value ="Häufigkeit, h(i)";
document.forms['f1'].w1.value = array[0][0];
document.forms['f1'].h1.value = array[0][1]+" "+ (array[0][1]*100/i).toFixed(1) + " %";
document.forms['f1'].w3.value = array[1][0];
document.forms['f1'].h2.value = array[1][1]+" "+ (array[1][1]*100/i).toFixed(1) + " %";
document.forms['f1'].w5.value = array[2][0];
document.forms['f1'].h3.value = array[2][1]+" "+ (array[2][1]*100/i).toFixed(1) + " %";
document.forms['f1'].w7.value = array[3][0];
document.forms['f1'].h4.value = array[3][1]+" "+ (array[3][1]*100/i).toFixed(1) + " %";
document.forms['f1'].w9.value = array[4][0];
document.forms['f1'].h5.value = array[4][1]+" "+ (array[4][1]*100/i).toFixed(1) + " %";
document.forms['f1'].w11.value = array[5][0];
document.forms['f1'].h6.value = array[5][1]+" "+ (array[5][1]*100/i).toFixed(1) + " %";
document.forms['f1'].w13.value = array[6][0];
document.forms['f1'].h7.value = array[6][1]+" "+ (array[6][1]*100/i).toFixed(1) + " %";
document.forms['f1'].w15.value = array[7][0];
document.forms['f1'].h8.value = array[7][1]+" "+ (array[7][1]*100/i).toFixed(1) + " %";
document.forms['f1'].w17.value = array[8][0];
document.forms['f1'].h9.value = array[8][1]+" "+ (array[8][1]*100/i).toFixed(1) + " %";
document.forms['f1'].w19.value = array[9][0];
document.forms['f1'].h10.value = array[9][1]+" "+ (array[9][1]*100/i).toFixed(1) + " %";
}
</script>
</head>
<body>
<h3>Text-Statistik</h3>
<form id="f1" action="">
<p>
<label for = "text"><strong> Eingabetext: </strong></label><br/>
<textarea name="textarea_in" cols="70" rows="20"></textarea><br/><br/>
<button type ="button" onclick = "auswerten()"> Auswerten </button>
<button type ="reset"> Neu </button><br/><br/>
<label for ="anzahl">Anzahl der Wörter: </label>
<input type = "text" id="anzahl" name = "anzahl" readonly = "readonly" size = "4" /> <br/><br/>
<input type = "text" readonly = "readonly" /><input type = "text" readonly = "readonly" size = "13"/><br/>
<input type = "text" id="w1"readonly = "readonly" /><input type = "text" id="h1" readonly = "readonly" size = "13"/><br/>
<input type = "text" id="w3"readonly = "readonly" /><input type = "text" id="h2" readonly = "readonly" size = "13"/><br/>
<input type = "text" id="w5"readonly = "readonly" /><input type = "text" id="h3" readonly = "readonly" size = "13"/><br/>
<input type = "text" id="w7"readonly = "readonly" /><input type = "text" id="h4" readonly = "readonly" size = "13"/><br/>
<input type = "text" id="w9"readonly = "readonly" /><input type = "text" id="h5" readonly = "readonly" size = "13"/><br/>
<input type = "text" id="w11"readonly = "readonly" /><input type = "text" id="h6" readonly = "readonly" size = "13"/><br/>
<input type = "text" id="w13"readonly = "readonly" /><input type = "text" id="h7" readonly = "readonly" size = "13"/><br/>
<input type = "text" id="w15"readonly = "readonly" /><input type = "text" id="h8" readonly = "readonly" size = "13"/><br/>
<input type = "text" id="w17"readonly = "readonly" /><input type = "text" id="h9" readonly = "readonly" size = "13"/><br/>
<input type = "text" id="w19"readonly = "readonly" /><input type = "text" id="h10" readonly = "readonly" size = "13"/><br/>
</p>
</form>
</body>
</html>
Zuletzt bearbeitet: