Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Jul 2004
    Location
    UK
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation need a little help with my loop

    hey ppl,
    i mtrying to implement a java scrip as a function which basically gets two numbers from the screen and multiplies them and then places the new
    number onto another field.

    but the ticky thing for me is the fact that the fields that the numbers come from are variable variables eg: product1, product2, product 3 (in a loop where i is incremented <input name='product$i' value='$product>.'

    now im trying to do a similar thing is javascript and the code i have come up with is:
    Code:
    function do_math() {
    var B = 1
    Var num= A;
    while (B < num) {   
    var quantity = eval(document.step5.quantity[B].value)
    var price = eval(document.step5.price[B].value)
    var calprice = quantity * price
    document.step5.cal[B].value= calprice;
    }
    can anyone help me & btw is this question really really stoopid?
    Last edited by earthsiege; 07-17-2004 at 04:17 PM.

  • #2
    Regular Coder
    Join Date
    Jun 2004
    Posts
    565
    Thanks
    0
    Thanked 18 Times in 18 Posts
    Code:
    function do_math() {
    Var num= A;
    for(var B = 1; B < num; B++) {   
      var quantity = new Number(document.step5['quantity' +B].value);
      var price = new Number(document.step5['price' +B].value);
      var calprice = quantity * price
      document.step5.['cal' +B].value= calprice;
    }
    This should work if you have A assigned a value before.

    dumpfi
    Last edited by dumpfi; 07-17-2004 at 04:40 PM.

  • #3
    New Coder
    Join Date
    Jul 2004
    Location
    UK
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts
    A is a value that ive passed on from the page before.
    does that make any problems, should it be $A instead. ne way the code provided above didnt work.
    Thanx for the help though.
    im still open to any suggestions

  • #4
    Regular Coder
    Join Date
    Jun 2004
    Posts
    565
    Thanks
    0
    Thanked 18 Times in 18 Posts
    I've edited it. If it still doesn't work post a sample source code of your page.

    dumpfi

  • #5
    New Coder
    Join Date
    Jul 2004
    Location
    UK
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanx for the reply raf, il try it out and post the results asap.

  • #6
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ne way the code provided ...
    Please post the results in english so that we can read your reply....

  • #7
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Willy Duitt's request may seem a little rude at first glance but I want to assure you it's not. A lot of the people who both look for help here and who provide help here do not necessarily know english as their first language so they've already got an extra barrier to understanding in their way. When you start using slang expressions and simplified spelling it makes it even harder for those people. Since as I stated some of them are providing help, you may be foreclosing some of the help you can receive by making yourself unintelligable.

    So help yourself by avoiding the the "instant messaging" style abbreviations and "cute" spellings.
    Check out the Forum Search. It's the short path to getting great results from this forum.

  • #8
    New Coder
    Join Date
    Jul 2004
    Location
    UK
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts

    i guess when you put it that way,.......

    Thabks for the insight Roy and i totally understand what your trying to say.
    Its going to be hard but im going to try and be as textbook as i can from now on. thanks for all the help anyway, youve all been a great help.


  •  

    Posting Permissions

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