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 9 of 9
  1. #1
    New Coder
    Join Date
    Jul 2004
    Location
    UK
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts

    !!Noob needing help!!

    hey ppl,
    usually all my work is with Php but recently ive had to get with the times and start using java but im having series of problems.

    im writing simple java code that multiplies two numbers together from two fileds but the thing is the two fileds keep are inside a php loop and the field names keep changing as the loop goes foreward (us till with me? ).
    eg.
    while $i < $b
    <input name="moh$i" etc>
    $i++;
    endwhile;

    .....
    is there anyway of doing the same thing in my java script so that the address field change in a loop similair to th one above?


  • #2
    New Coder
    Join Date
    May 2004
    Posts
    72
    Thanks
    0
    Thanked 0 Times in 0 Posts
    your incrementing $i each time the loop passes through... therefore your input box will be known as moh1 the first time, followed by moh2 the second and so forth....

    If you already know this then no.. im not with you! he he he
    "The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect."

    --Tim Berners-Lee, W3C Director and Inventor of the World Wide Web

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

    Question

    no s*** sherlock!lol
    i know that each time the input name changes but my problem is the fact that i need the ame type of thing for the java script but i already tried putting it into a loop which didnt work....

  • #4
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    Somthing like this?

    Code:
    <script type="text/javascript">
    var i=0;
    var b=4;
    var str="";
    while(i<b)
    {
    	str+='<input type="text" name="moh'+i+'">';
    	i++;
    	
    }
    document.write(str);
    	
    </script>
    Basscyst

    PS. It's not nice to be rude to people who are helping you.
    Last edited by Basscyst; 07-12-2004 at 05:06 PM.
    Helping to build a bigger box. - Adam Matthews

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

    Question no no no.....

    I think that i may have put my question forward ina dodgy way.
    look weve got two files lets say a&b:
    while ($i < $n):
    <input name='a$i' onchange="do_math()">;
    <input name='b$i'>;
    <input name='collection$i'>;
    $i ++;
    endwhile
    okay now we want to have an "onchange" function called do_math() in java script which multiplies a by b but THIS HAS TO BE DONE N-1 times.....
    and each a and b is a different value being read of a mysql database.
    okay,
    wot would it look like ive got somefin like below but it doesnt work, anyone help?

    <script language="JavaScript" >
    function do_math()
    for (i=1; i <= $A; i = i + 1) {
    var b = eval(document.step5.a$i.value)
    var a = eval(document.step5.b$i.value)
    var multi = a * b
    document.step5.collection.value= multi;
    }
    </script>

  • #6
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    In your 2nd shown function

    This should be all you need:

    Code:
    function do_math(){
      for (i=1; i <= $A; i++) {
         var b = document.step5.a$i.value
         var a = document.step5.b$i.value
         var multi = a * b
         document.step5.collection.value= multi;
    }
    In the first function I'm not sure what you are asking do you want that done in JS?

    The above should work with no problem assuming there is a clientside value for $A.

    Basscyst
    Helping to build a bigger box. - Adam Matthews

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

    uhhh, okay i guess

    thats nearly wot i was thinkin but its still not workin,
    if theres ne1 else who can help me pls post a reply...sob...sob...sob

  • #8
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,966
    Thanks
    0
    Thanked 236 Times in 233 Posts
    Is this what you want?
    Code:
    while ($i < $n):
    <input name='a$i' onchange="do_math(this,'b$i','collection$i')">;
    <input name='b$i'>;
    <input name='collection$i'>;
    $i ++;
    endwhile
    ...
    function do_math(objA, bName, collName){
       objA.form.elements[collName].value=objA.value*objA.form.elements[bName].value;
    }

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

    you are the man

    yo man,
    you are the holy man.
    thanks a lot.
    dont know why i didnt think of it that way myself...lol
    thanks anyway.


  •  

    Posting Permissions

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