RE: dynamic addition

Results 1 to 7 of 7

Thread: RE: dynamic addition

  1. #1
    Join Date
    Dec 1969
    Posts
    425

    Default RE: dynamic addition

    I have a cart which repeats at checkout, our client wants to charge delivery per weight, so I added a recordset into the repeat region to display the weight for each item in the cart (display weight where recordset_code = cart_code This works fine), I then created a loop which adds 1 to the field name<BR><BR>weight_&#060;%=MM_loop +1%&#062; value=recordset.weight<BR><BR>what is the best way to add the total up? I tried<BR><BR>a JS script which returns the error document.shop.weight_&#039; is null or not an object<BR><BR> function myCOUNT() {<BR> var i = document.shop.totalcount.value;<BR> var n = 1<BR> for(n=1;n&#060;i;++n) {<BR> alert(document.shop.weight_[n].value)<BR> }<BR> }<BR>//this should alert each total so we know we can collect the weights<BR><BR>is there a way of dynamically calculating this in asp?

  2. #2
    Join Date
    Dec 1969
    Posts
    787

    Default RE: dynamic addition

    for(n=1;n&#060;i;++n) <BR><BR>try for(n=1;n&#060;i;n++)<BR><BR>you&#039;re starting from n=2 with your code and ending one too high, (no value for n=i+1)<BR><BR><BR><BR>

  3. #3
    Join Date
    Dec 1969
    Posts
    425

    Default RE: dynamic addition

    onClick="myCOUNT(&#060;% for i = 1 to MM_loop %&#062;&#060;%=left(response.write("&#039;weight_" & i & "&#039;,") - 1)%&#062; &#060;% next %&#062;)"<BR><BR>ok what about this?

  4. #4
    Join Date
    Dec 1969
    Posts
    425

    Default RE: dynamic addition

    how can I repeat this loop and then loose the end comma?


  5. #5
    Join Date
    Dec 1969
    Posts
    96,118

    Default That answer is just plain wrong

    To prove it, do this:<BR><BR>&#060;HTML&#062;&#060;BODY&#062;<BR>& #060;SCRIPT&#062;<BR>document.write("first: ");<BR>for(n=1;n&#060;i;++n) <BR>{<BR> document.write(" " + n);<BR>}<BR>document.write("&#060;P&#062;second: ");<BR>for(n=1;n&#060;i;n++)<BR>{<BR> document.write(" " + n);<BR>}<BR>&#060;/SCRIPT&#062;<BR>&#060;/BODY&#062;&#060;/HTML&#062;<BR><BR>**********<BR><BR>I think that "pill" needs to go re-learn how "for" works in JavaScript (and Java and C and C++).<BR><BR>HINT: The increment is *NOT* done before the loop starts. It is done at the "bottom" of the loop, only.<BR><BR><BR>

  6. #6
    Join Date
    Dec 1969
    Posts
    96,118

    Default Do you know...

    ...what that means????<BR><BR>*ALL* ASP code...that is, *ALL* code between &#060;% and %&#062;...is executed ON THE SERVER before *anything* is sent to the browser.<BR><BR>So assuming the MM_loop is (say) 4, that will end up putting this into your HTML code:<BR><BR>onClick="myCount(&#039;weight_1&#039; ,&#039;weight_2&#039;,&#039;weight_3&#039;,&#039;w eight_4&#039;)"<BR><BR>Is that really what you want? And do you know how to handle a variable number of arguments in JavaScript code???<BR><BR>I think you are making a mistake with this approach. I&#039;m sure it can be made to work, but not easily.<BR>

  7. #7
    Join Date
    Dec 1969
    Posts
    96,118

    Default Just fix your JS code...

    Where did you get the idea you could do this:<BR> document.shop.weight_[n]<BR>????<BR><BR>function myCOUNT() <BR>{<BR> var myForm = document.shop;<BR> var total = 0;<BR> for( var n = 1; n &#060; parseInt(myForm.totalcount.value); ++n )<BR> {<BR> total += parseFloat( myForm.elements("weight_"+n).value );<BR> }<BR> alert("The total of the weights is " + total);<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
  •