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.