#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    3
    Rep Power
    0

    Unhappy php and javascript problem


    I have a code in which there are array names for text boxes...the code looks like this

    [PHP] echo "<td><input type=text size=13 name=\"quantity[$i]\"></td>\n";
    echo "<td><input type=text size=13 name=\"production[$i]\"></td>\n";
    echo "<td><input type=text size=13 name=\"extAmt[$i]\" onFocus=\"addExtAmt($i);\"></td>\n";
    [PHP]

    i want to calculate the extAmt value depending on the values in quantity[] and production[]. i.e extAmt = quantity * production.

    i would do it if they were staright variables...but does anybody know how do to it when ure variables are arrays..

    I came up with some solution, but its not working..if u think I am in right direction, just let me know where I am wrong

    my javascript is

    function addExtAmt(count){
    var varu;
    qtEl = document.frm.elements['quantity[]'];
    prEl = document.frm.elements['production[]'];
    eaEl = document.frm.elements['extAmt[]'];
    varu = ((parseInt(document.frm.qtEl[count].value))*(parseFloat(document.frm.prEl[count].value)));
    varu = round(varu);
    document.frm.eaEl[count].value = varu;
    }


    Regards,
    Ashay
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Amsterdam, NL
    Posts
    6
    Rep Power
    0
    What error message do you get? If the page loads, it probably is the javascript part. In the line before last, "varu = round(varu);", are you sure that "round" is an accepted abbreviation of "Math.round"?
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Location
    Barcelona
    Posts
    133
    Rep Power
    12
    also make sure addExtAmt is executed onload, not before, otherwise you'll get undefined error messages
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    3
    Rep Power
    0

    hi


    I get errors on focussing the textbox extAmt.

    round is a funtion which I have written, so dont worry abt that.

    i didnt understand why u said onLoad..i mean I am getting the error only when I focus on that texbox..so i guess I am right in that terms
  8. #5
  9. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Location
    Barcelona
    Posts
    133
    Rep Power
    12
    yeah, wondered just in case. What error message do you get? Can we see a complete test page? btw, never seen id's or names filled with an array element... might be that...
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    3
    Rep Power
    0
    The error i get is object required..
    I have reached this stage..
    I do this
    echo "<td><input type=text size=13 name=\"quantity[$i]\" id=\"quantity_$i\"></td>\n";
    echo "<td><input type=text size=13 name=\"production[$i]\" id=\"production_$i\"></td>\n";
    echo "<td><input type=text size=13 name=\"extAmt[$i]\" id=\"extAmt_$i\" onFocus=\"addExtAmt($i);\"></td>\n";

    and the javascript i wrote is this:

    function addExtAmt(count){
    var varu;
    var temp = count;
    var qtObj = document.getElementById("quantity_"+temp);
    var qt_value = qtObj.value;
    var prObj = document.getElementById("production_"+temp);
    var pr_value = prObj.value;
    varu = ((parseInt(qt_value))*(parseFloat(pr_value)));
    varu = round(varu);
    var exObj = document.getElementById("extAmt_"+temp);
    exObj.value = varu;
    }


    but its not working
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2001
    Posts
    178
    Rep Power
    14
    Try using eval function

    change this
    var qtObj = document.getElementById("quantity_"+temp);

    to this
    var qtObj = eval(document.getElementById("quantity_"+temp));

    do this for the other obj variable too.

    Im not very sure about this but give it a try

IMN logo majestic logo threadwatch logo seochat tools logo