How do I do this?

Results 1 to 7 of 7

Thread: How do I do this?

  1. #1
    William Guest

    Default How do I do this?

    If I do this comparision:<BR><BR>temp = document.User.Person1.value<BR><BR>temp then equals the value of that field. When I do this:<BR><BR>temp = "document.User.Person" + i + ".value" (where i=1), of course it is now document.User.Person1.value<BR><BR>How can I construct that dynamically so that I can change that nubmer but still get the value from the form field?

  2. #2
    Join Date
    Dec 1969

    Default RE: How do I do this?

    temp = eval("document.User.Person" + i + ".value"); <BR><BR>try and be more descriptive in your title next time though...;-)<BR><BR>J

  3. #3
    lagerBoy Guest

    Default Nearly there for me, but not quite.

    I&#039ve got a form that has rows of products. I&#039m using a naming convention such as prod1, prod2 etc. for each of the select boxes.<BR><BR>Each product has a disabled SELECT field called price1, price2 etc.<BR><BR>I&#039m capturing the onblur event for each select box and it is my desire to calculate a Grand total based on (prod1*price1)+(prod2*price2) .... etc<BR><BR>At the moment I haven&#039t been able to figure this out so I&#039m passing a value into the onblur event such as onblur(1), this tells the function which SELECT box was blurred and calculates its value then adds it to the value in the disabled Grand total SELECT box.<BR><BR>It would still be better for me to work out how to do a FOR EACH thingy and treat the fields as an array thingy. I haven&#039t done much object oriented stuff in JScript, and I didn&#039t listen very well at school so please help or it&#039s goodbyeWorld for me!

  4. #4
    lagerBoy Guest

    Default Running commentary .... (this could be fun)

    Allright, I&#039ll start answering my own question here.<BR><BR>Perhaps I should include a hidden field in the form that says how many items, then use that as my counter integer.<BR><BR>Stay tuned, I may get there!!

  5. #5
    Join Date
    Dec 1969

    Default RE: Running commentary .... (this could be fun)

    nah, create a global javascript variable, it&#039s less hassle. and use the onchange event instead of onblur<BR><BR>to make a global javascript variable, define it outside your function blocks with var <BR><BR>i.e.<BR><BR>var x = 0<BR><BR>function myfunction(){<BR>x++<BR>}<BR><BR>what that acieves is to show you how many times myfunction() has been called. you can use that to hold totals, or you can just re-calc the whole thing<BR><BR>jason

  6. #6
    lagerBoy Guest

    Default I'm not sure that I agree.

    Are you sure that is the way to go, I mean I would still have to loop through the elements on the form and do a re-calc anyway? y/n?<BR><BR>Either that or capture a before change and after change value and calculate the difference.<BR><BR>Anyway you&#039re the JScript guru - I&#039ll leave those minor details for you to sift through, in the meantime here is the next enthralling installment of Dummies do Objects.function creArrayFunction()<BR>{<BR>// var myArray = New Array();<BR> var myForm =;<BR> var intItems = myForm.items.value;<BR> <BR>// Start looping through the form<BR> for(loop=0; loop&#060;=intItems; loop++)<BR> {<BR> //alert(loop)<BR>// Loop through the elements on the form<BR> for(subloop=0; subloop&#060;=myForm.elements.length; subloop++)<BR> {<BR> //alert(subloop)<BR> }<BR> }<BR>}<BR>--&#062;<BR>&#060;/script&#062;<BR><BR>

  7. #7
    lagerBoy Guest

    Default The [preliminary] result - subject to scrutiny.

    Rem: Form consists of x rows each row has 3 fields called:<BR>First row field is a named a number: 1<BR>Second row field is called: unit1<BR>Third row field is called: subtot1<BR><BR>There is also a hidden field called: items<BR>And a Grand Total field called: total<BR>The form is called: shopping<BR><BR>Each input field calls the creArrayFunction() on activation of the BLUR event.<BR><BR>My pain is your gain. Enjoy. :)<BR>******************************************** ****<BR><BR>var intGrandTotal = 0<BR><BR>function bodLoader()<BR>{<BR>intGrandTotal =;<BR>}<B R>function creArrayFunction()<BR>{<BR>// initialize our object variable.<BR> var myForm =;<BR>// capture the hidden value showing how many rows in form.<BR> var intItems = myForm.items.value;<BR>// initialize counter variable for looping through form elements.<BR> var intElements = myForm.elements.length - 1;<BR>// Variable to accumulate the row subtotals.<BR> myLoopSubTotal = 0;<BR> <BR>// Start looping through the form<BR> for(var loop=1; loop&#060;=intItems; loop++) <BR> {<BR> var myCurrentQty = 0;<BR> var myCurrentPrice = 0;<BR><BR>// Loop through the elements on the form<BR> for(subloop=0; subloop&#060;=intElements; subloop++)<BR> {<BR> var myCurrentItem = myForm.elements[subloop].name<BR> if(myCurrentItem == loop)<BR> {<BR> myCurrentQty = myForm.elements[subloop].value<BR> }<BR> if(myCurrentItem == "unit"+loop)<BR> {<BR> myCurrentPrice = myForm.elements[subloop].value<BR> }<BR> if(myCurrentItem == "subtot"+loop)<BR> {<BR> intRowTotal = (myCurrentQty*myCurrentPrice);<BR>[subloop].value = intRowTotal<BR> }<BR> }<BR> myLoopSubTotal = (myLoopSubTotal + intRowTotal);<BR> }<BR> = myLoopSubTotal;<BR> myLoopSubTotal = 0;<BR>}<BR>--&#062;<BR>&#060;/script&#062;

Posting Permissions

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