HTML, JavaScript And CSS Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingHTML, JavaScript And CSS Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old November 19th, 2003, 05:18 AM
Ethena Ethena is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Denmark
Posts: 1 Ethena User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old December 3rd, 2003, 11:24 AM
MichaelM MichaelM is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: Virginia Beach, VA
Posts: 34 MichaelM User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 12 m 10 sec
Reputation Power: 5
<Script>
var amo = 0;
function addFields(amount, mySpan){
&nbsp;&nbsp;&nbsp;&nbsp;var place, contents;
&nbsp;&nbsp;&nbsp;&nbsp;amo = amount.value;
&nbsp;&nbsp;&nbsp;&nbsp;place = document.forms.myForm.all(mySpan);
&nbsp;&nbsp;&nbsp;&nbsp;if (amo > 0) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;contents = "<TABLE>";
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (var i=1; i<=amo; ++i) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;contents += "<TR><TD>" + i + ". result:</TD><TD><INPUT TYPE='text' NAME='" + mySpan + i + "'></TD></TR>";
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;contents += "</TABLE>";
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;place.innerHTML = contents;
&nbsp;&nbsp;&nbsp;&nbsp;}
}

function analyze() {
&nbsp;&nbsp;&nbsp;&nbsp;var l, h, t, a;
&nbsp;&nbsp;&nbsp;&nbsp;t = 0;
&nbsp;&nbsp;&nbsp;&nbsp;if(amo > 0) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;l = eval("document.myForm.abc1.value");
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h = eval("document.myForm.abc1.value");
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for(i=1; i<=amo; i++) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var val = eval("document.myForm.abc" + i + ".value");
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;val = parseFloat(val);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(val < l) l = val;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(val > h) h = val;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t = t + val;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;document.myForm.low.value = l;
&nbsp;&nbsp;&nbsp;&nbsp;document.myForm.high.value = h;
&nbsp;&nbsp;&nbsp;&nbsp;document.myForm.tot.value = t;
&nbsp;&nbsp;&nbsp;&nbsp;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>

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingHTML, JavaScript And CSS Help > Dynamic Field-names JavaScript/ASP


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT