Dynamic update of the counter on an ASP page

Results 1 to 2 of 2

Thread: Dynamic update of the counter on an ASP page

  1. #1
    Join Date
    Dec 1969

    Default Dynamic update of the counter on an ASP page

    Hello, <BR><BR>I have a page with say 100 items and for each item you can allocate some number of points. Is there a way to update a counter on the top of the page to reflect the count whenever a user allocates points to an item or deallocates the points previously assigned. <BR><BR>I populate the initial counter values from the database, but I dont know how can i do it dynamically reflect the updates on the same page without submitting it. <BR><BR>Thanks <BR>MMS

  2. #2
    Join Date
    Dec 1969

    Default What has ASP to do with it???

    Do you mean something like this:<BR><BR><BR>&#060;FORM ...&#062;<BR><BR>Total points allocated: <BR>&#060;INPUT Name="Total" Value="63" onFocus="this.form.User1.focus();"&#062;<BR><BR>Us er 1 points: &#060;INPUT Name="User1" Value="17" onChange="updateTotal(this);"&#062;<BR>User 2 points: &#060;INPUT Name="User2" Value="21" onChange="updateTotal(this);"&#062;<BR>User 3 points: &#060;INPUT Name="User3" Value="12" onChange="updateTotal(this);"&#062;<BR>User 4 points: &#060;INPUT Name="User4" Value="13" onChange="updateTotal(this);"&#062;<BR>...<BR>&#06 0;/FORM&#062;<BR><BR>&#060;SCRIPT Language="JavaScript"&#062;<BR>function updateTotal(fld)<BR>{<BR>&nbsp; &nbsp; var frm = fld.form;<BR>&nbsp; &nbsp; var tot = 0;<BR>&nbsp; &nbsp; for ( var i = 1; i &#060;= 4; ++i )<BR>&nbsp; &nbsp; {<BR>&nbsp; &nbsp; &nbsp; &nbsp; tot += parseInt( frm.elements["User"+i].value );<BR>&nbsp; &nbsp; }<BR>&nbsp; &nbsp; frm.Total.value = tot;<BR>}<BR>&#060;/SCRIPT&#062;<BR><BR>You might, however, want to be smarter than that. For example, remember the prior value of each UserN field and, if you get "NaN" from the parseInt you restore the value and put up an alert telling the idiot user to enter only a whole number.<BR><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts