witam,
jako ze js to nie mój żywioł dojście do czegoś takiego zajęło mi dłuższą chwilę
<script language="JavaScript"><!-- function update(theform) {
with(Math)
{
var a=parseFloat(theform.a.value);
var b=parseFloat(theform.b.value);
var c=parseFloat(theform.c.value);
var d=parseFloat(theform.d.value);
var e=parseFloat(theform.e.value);
var f=parseFloat(theform.f.value);
var g=parseFloat(theform.g.value);
var h=parseFloat(theform.h.value);
var i=parseFloat(theform.i.value);
var j=parseFloat(theform.j.value);
var tmp=(a+b+c+d+e+f+g+h+i+j)/10;
if (isNaN(tmp)) {tmp="Popraw wartosci"};
theform.x.value=tmp;
}
}
<body bgcolor="#ffffff" onLoad="update(document.mathForm);"> <form method=get onSubmit="return false;" name=mathForm> <table border="0" cellspacing="1">
<tr><th bgcolor="#cccccc" width=150>a
</th><td bgcolor="#eeeeee"><input type=text name="a" value="" onChange="update(this.form)"></td></tr> <tr><th bgcolor="#cccccc" width=150>b
</th><td bgcolor="#eeeeee"><input type=text name="b" value="" onChange="update(this.form)"></td></tr> <tr><th bgcolor="#cccccc" width=150>c
</th><td bgcolor="#eeeeee"><input type=text name="c" value="" onChange="update(this.form)"></td></tr> <tr><th bgcolor="#cccccc" width=150>d
</th><td bgcolor="#eeeeee"><input type=text name="d" value="" onChange="update(this.form)"></td></tr> <tr><th bgcolor="#cccccc" width=150>e
</th><td bgcolor="#eeeeee"><input type=text name="e" value="" onChange="update(this.form)"></td></tr> <tr><th bgcolor="#cccccc" width=150>f
</th><td bgcolor="#eeeeee"><input type=text name="f" value="" onChange="update(this.form)"></td></tr> <tr><th bgcolor="#cccccc" width=150>g
</th><td bgcolor="#eeeeee"><input type=text name="g" value="" onChange="update(this.form)"></td></tr> <tr><th bgcolor="#cccccc" width=150>h
</th><td bgcolor="#eeeeee"><input type=text name="h" value="" onChange="update(this.form)"></td></tr> <tr><th bgcolor="#cccccc" width=150>i
</th><td bgcolor="#eeeeee"><input type=text name="i" value="" onChange="update(this.form)"></td></tr> <tr><th bgcolor="#cccccc" width=150>j
</th><td bgcolor="#eeeeee"><input type=text name="j" value="" onChange="update(this.form)"></td></tr>
<p><input type=button value="Oblicz" onClick="update(this.form)"> |
<input type=reset value="Reset"></p> <table border=0 cellspacing=1>
<tr><th bgcolor="#cccccc" width=150>Srednia arytmetyczna
</th><td bgcolor="#eeeeee"><input type=text name="x" value="" onChange="alert('Nie zmieniaj tej wartosci w tym okienku!');update(this.form)"></td></tr>
Jednak nie wszystko jestem w stanie osiągnąć
przede wszystkim chciałbym aby średnia była liczona tylko z tylu pól ile zostało wypełnionych (jesli jest 1, 2 i 6 pole to z trzech itd)
druga sprawa to aby dało się wprowadzić tylko wartości liczbowe od 1 do 6
trzecia sprawa to zaokraglenie sredniej do 2 miejsc po przecinku
i ewentualna czwarta aby srednia zmieniala sie dynamicznie bez potrzeby naciskania przycisku oblicz

za wszystkie wskazówki, przykłady, gotowe rozwiązania ( ;-) ) z góry dziekuje