|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Help: Dynamic Field-names JavaScript/ASP?
Help needed!
I'm trying to create a form, where the users specifies the amount of INPUT-fields needed to hold some analyses-results. Finally the lowest result, the highest result and the average of all the results is supposed to be placed in 3 new INPUT-fields automatically. The problem is, that the amount varies from one user to the other. AND ... this is supposed to be done for several different analyses-components. So far, I have managed to make the first part: In the Form for one of the components: <TABLE> <TR><TD>Amount of analyses-results:</TD> <TD><INPUT TYPE="text" NAME="abcAmount"></TD> <TD><INPUT TYPE="button" NAME="button1" VALUE="OK" OnClick="addFields(abcAmount, 'abc')"></TD> </TR> </TABLE><BR CLEAR="all"> <SPAN ID="abc" NAME="abc"></SPAN> The script: function addFields(amount, mySpan) { var place, contents, amo; amo = amount.value; place = document.forms.myForm.all(mySpan); if (amo > 0) { contents = "<TABLE>"; for (var i=1; i<=amo; ++i) { contents += "<TR><TD>" + i + ". result:</TD><TD><INPUT TYPE='text' NAME='" + mySpan + i + "'></TD></TR>"; } contents += "</TABLE>; place.innerHTML = contents; } } The difficult part is to find the lowest and highest result and the average, and get those placed in new INPUT-fields, because the names of the generated INPUT-fields varies depending of the amount of results. Last edited by Ethena : November 19th, 2003 at 08:00 AM. |
|
#2
|
|||
|
|||
|
<Script>
var amo = 0; function addFields(amount, mySpan){ var place, contents; amo = amount.value; place = document.forms.myForm.all(mySpan); if (amo > 0) { contents = "<TABLE>"; for (var i=1; i<=amo; ++i) { contents += "<TR><TD>" + i + ". result:</TD><TD><INPUT TYPE='text' NAME='" + mySpan + i + "'></TD></TR>"; } contents += "</TABLE>"; place.innerHTML = contents; } } function analyze() { var l, h, t, a; t = 0; if(amo > 0) { l = eval("document.myForm.abc1.value"); h = eval("document.myForm.abc1.value"); for(i=1; i<=amo; i++) { var val = eval("document.myForm.abc" + i + ".value"); val = parseFloat(val); if(val < l) l = val; if(val > h) h = val; t = t + val; } } document.myForm.low.value = l; document.myForm.high.value = h; document.myForm.tot.value = t; document.myForm.ave.value = t/amo; } </script> <form name="myForm"> <TABLE> <TR><TD>Amount of analyses-results:</TD> <TD><INPUT TYPE="text" NAME="abcAmount"></TD> <TD><INPUT TYPE="button" NAME="button1" VALUE="OK" OnClick="addFields(abcAmount, 'abc')"></TD> </TR> </TABLE><BR CLEAR="all"> <SPAN ID="abc" NAME="abc"></SPAN> <table> <tr><td><input type="button" onclick="analyze()" value="Analyze"></td></tr> <tr><td>Lowest Result:</td><td><input name="low"></td></tr> <tr><td>Highest Result:</td><td><input name="high"></td></tr> <tr><td>Total of Results:</td><td><input name="tot"></td></tr> <tr><td>Average Result:</td><td><input name="ave"></td></tr> </table> </form> |
![]() |
| Viewing: ASP Free Forums > Programming > HTML, JavaScript And CSS Help > Dynamic Field-names JavaScript/ASP |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|