#1
  1. No Profile Picture
    Lisa1958
    Guest
    Devshed Newbie (0 - 499 posts)
    I am doing so totaling on the fly with javascript. It works great in everything but IE3. Anyone know how I can get this to work in IE 3?

    The error I get is (this line) "'value' is not a number"

    document.input.f_stot.value= decimal(document.input.f_tot0.value * 1 + document.input.f_tot1.value * 1 + document.input.f_tot2.value * 1 + document.input.f_tot3.value * 1 + document.input.f_tot4.value * 1 + document.input.f_tot5.value * 1);
    document.input.finalTotal.value=document.input.f_stot.value
    }

    I have tried all sorts of variations on this code to force Javascript to see it as a number but none seem to work.

    thanks for any help!

    Lisa
  2. #2
  3. No Profile Picture
    Alison
    Guest
    Devshed Newbie (0 - 499 posts)
    It's hard to tell what exactly is going on here without seeing it in context, but...

    JavaScript considers any input from the user to be a string. So, you need to use something like the code below on each of your values to convert them to numbers.

    var input0 = parseFloat(document.input.f_tot0.value)

    You could also put parseFloat() around each of your values right when you do the calculation, rather than assigning them to a variable as I showed you above.

    I assume you were multiplying each by one in attempt to convert them to numbers. Doing so is not necessary (since it won't work anyway).
  4. #3
  5. No Profile Picture
    Lisa1958
    Guest
    Devshed Newbie (0 - 499 posts)
    I tried your recommendation and it worked great in IE3 which is where I was getting my error. But the same code gives me a NaN total in N4.5 which had no trouble with my original code.

    new code:

    newtotal = parseFloat(document.input.f_tot0.value) + parseFloat(document.input.f_tot1.value) + parseFloat(document.input.f_tot2.value) + parseFloat(document.input.f_tot3.value) + parseFloat(document.input.f_tot4.value) + parseFloat(document.input.f_tot5.value);
    document.input.f_stot.value= decimal(newtotal);
    document.input.finalTotal.value=document.input.f_stot.value}

    I hate to put a "use 4.0 or higher" but I will if I have too!
  6. #4
  7. No Profile Picture
    Alison
    Guest
    Devshed Newbie (0 - 499 posts)
    Since you've already converted your strings to numbers when you totaled them, you shouldn't need to do anything to the contents of your newtotal variable.

    I'm not sure what you're using "decimal()" for, unless it's a custom function somewhere else in your code. (As far as I know, it's not a valid method in JavaScript.)

    So, your next-to-the-last line of code should simply be:

    document.input.f_stot.value = newtotal;
  8. #5
  9. No Profile Picture
    Lisa1958
    Guest
    Devshed Newbie (0 - 499 posts)
    "decimal" is a function:

    // turn to decimal
    function decimal(num)
    {
    string = "" + num;
    number = string.length - string.indexOf('.');
    if (string.indexOf('.') == -1)
    return string + '.00';
    if (number == 1)
    return string + '00';
    if (number == 2)
    return string + '0';
    if (number > 3)
    return string.substring(0,string.length-number+3);
    return string;
    }

    the same total is repeated in form.f_stot and form.finalTotal
  10. #6
  11. No Profile Picture
    Alison
    Guest
    Devshed Newbie (0 - 499 posts)
    I made a minimal page in which to test your code, with six text input boxes to enter numbers in, and two fields to show the total. It worked fine in both IE 4 and Netscape 4.5.

    So it seems that if you're still having problems, they are caused by something elsewhere in your page and/or code.

Similar Threads

  1. "Value cannot be null. Parameter name: s"
    By mckracken83 in forum C Programming
    Replies: 1
    Last Post: September 11th, 2003, 01:08 PM

IMN logo majestic logo threadwatch logo seochat tools logo