SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2004
    Location
    Ottawa, Ont. Canada
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    problem with Multiple text boxes using formated numbers

    Hello

    I'm primarily a database programmer (Mysql and PHP) but I have some Javascript programming and I have been programming in other languages for over 25 years.

    On to my problem:

    I'm trying the create a function in Javascript which will take a variable from three different text boxes and show the net result in a fourth text box that is ReadOnly. This is all on the same page. All three text boxes have other Javascript scripts formatting the value in the text boxes.

    Real example (simplified)


    Mortgage Amount _______________ // formatted into $ with "," & numbers only.

    Commission % _______________ // formatted into numbers only.

    OR

    Commission $ _______________ // formatted into $ with "," & numbers only.

    The result should be placed in a ReadOnly text box allowing the user to override the percentage using the Dollar input text box. The override is not necessary for the function.

    The real example is showing one Commission however the function must calculate for three separate Commissions (1, 2 & 3) and for two different sections, Mortgage and Investment. There are 6 output ReadOnly text boxes on the form.

    The problem is there is no output into the fourth ReadOnly text box.

    Here is the function code: below it will be the calling routine:
    ___________________________________________________________
    <script>

    function tot_commissions()
    {
    re = /^\$|,/g;
    var m_amnt = (+document.getElementById('input10').value.replace(re, ""));
    var m_com1p = (+document.getElementById('input11').value.replace(re, ""));
    var m_com1d = (+document.getElementById('input12').value.replace(re, ""));
    var m_com2p = (+document.getElementById('input14').value.replace(re, ""));
    var m_com2d = (+document.getElementById('input15').value.replace(re, ""));
    var m_com3p = (+document.getElementById('input17').value.replace(re, ""));
    var m_com3d = (+document.getElementById('input18').value.replace(re, ""));
    var m_f_com1 = 0;
    var m_f_com2 = 0;
    var m_f_com3 = 0;

    var i_amnt = (+document.getElementById('input23').value.replace(re, ""));
    var i_com1p = (+document.getElementById('input28').value.replace(re, ""));
    var i_com1d = (+document.getElementById('input29').value.replace(re, ""));
    var i_com2p = (+document.getElementById('input31').value.replace(re, ""));
    var i_com2d = (+document.getElementById('input32').value.replace(re, ""));
    var i_com3p = (+document.getElementById('input34').value.replace(re, ""));
    var i_com3d = (+document.getElementById('input35').value.replace(re, ""));
    var i_f_com1 = 0;
    var i_f_com2 = 0;
    var i_f_com3 = 0;

    if (m_amnt <> 'NaN' || m_amnt > 0)
    {
    if (m_com1d)
    {
    m_f_com1 = m_com1d;
    }
    else
    {
    m_f_com1 = m_com1p * m_amnt;
    }

    if (m_com2d)
    {
    m_f_com2 = m_com2d;
    }
    else
    {
    m_f_com2 = m_com2p * m_amnt;
    }

    if (m_com3d)
    {
    m_f_com3 = m_com3d;
    }
    else
    {
    m_f_com3 = m_com3p * m_amnt;
    }

    }

    if (m_f_com1 < 1 || m_f_com1 == "NaN")
    {
    m_f_com1 = 'N/A';
    }

    if (m_f_com2 < 1 || m_f_com2 == "NaN")
    {
    m_f_com2 = 'N/A';
    }

    if (m_f_com3 < 1 || m_f_com3 == "NaN")
    {
    m_f_com3 = 'N/A';
    }


    if (i_amnt)
    {
    if (i_com1d)
    {
    i_f_com1 = i_com1d;
    }
    else
    {
    i_f_com1 = i_com1p * i_amnt;
    }

    if (i_com2d)
    {
    i_f_com2 = i_com2d;
    }
    else
    {
    i_f_com2 = i_com2p * i_amnt;
    }

    if (i_com3d)
    {
    i_f_com3 = i_com3d;
    }
    else
    {
    i_f_com3 = i_com3p * i_amnt;
    }

    }

    if (i_f_com1 < 1 || i_f_com1 == "NaN")
    {
    i_f_com1 = 'N/A';
    }

    if (i_f_com2 < 1 || i_f_com2 == "NaN")
    {
    i_f_com2 = 'N/A';
    }

    if (i_f_com3 < 1 || i_f_com3 == "NaN")
    {
    i_f_com3 = 'N/A';
    }

    document.getElementById('final1').value = m_f_com1;
    document.getElementById('final2').value = m_f_com2;
    document.getElementById('final3').value = m_f_com3;

    document.getElementById('final4').value = i_f_com1;
    document.getElementById('final5').value = i_f_com2;
    document.getElementById('final6').value = i_f_com3;

    }

    </script>
    ________________________________________________________________

    The input text boxes are created through PHP while loop with a switch statement:
    ______________________________________________________________
    case "commission_1_p":
    case "commission_2_p":
    case "commission_3_p":
    case "i_consult_1_p":
    case "i_consult_2_p":
    case "i_consult_3_p":
    case "m_consult_1_p":
    case "m_consult_2_p":
    case "m_consult_3_p":
    print "%";
    ?>
    <input type=text name="input<? print $y; ?>" size= 5 value = "<? print $array1[$y][7]; ?>" onKeyPress="return numbers(this, event)" onKeyup="tot_commissions()">
    <?

    print " or $";
    $y = $y + 1;
    ?>
    <input type=text name="input<? print $y; ?>" size= 8 value = "<? print $array1[$y][7]; ?>" onKeyPress="return(currencyFormat(this,',','.',event))">
    <?
    $y = $y + 1;
    $s = $s + 1;
    print " ID # ";
    print '<input type=text name="input'.$y.'" size= 8 value = "'. $array1[$y][7].'">';
    print '&nbsp;';
    print '<INPUT TYPE="button" VALUE="CONSULTANT" onClick="showList'.$s.'()">';
    print '&nbsp;=$';
    print '<input type=text name="final'.$s.'" size= 8 readonly>';

    break;
    ______________________________________________________________

    This can be seen operating live at:

    http://www.abistrategies.com/level1/management

    Under Client select Pipeline and hit Client button and choose any client in the list. All this data is made up data for testing purposes.

    Any help would be appreciated.

  2. #2
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by phall472 View Post
    Hello

    I'm primarily a database programmer (Mysql and PHP) but I have some Javascript programming and I have been programming in other languages for over 25 years.
    In that case you should know that language compilers and interpreters generate messages to indicate syntax and other errors.
    In this case the first error encountered is that there is no <> operator in JavaScript.
    If you have an algorithmic problem that's fine, but nobody wants to be referred to code that generates unacknowledged errors.
    In Mozilla/Firefox, the console is under the Tools menu.
    Tab-indentation is a crime against humanity.

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2004
    Location
    Ottawa, Ont. Canada
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello

    That was my error. I keep on forgetting that Javascript message in the Status bar.

    I have only been using Javascript for a little over a month and I thought that not equal <> would work.

    When I changed <> to != it removed the error.

    Thank you


Bookmarks

Posting Permissions

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