Hi all, this is my original code that was working, but my organization decided to move away from the use of percentage work to hours work and to retain the old percentage work in the database and the new works should be hours work. when the form that contain the percentage is loaded the percentage work should be loaded and the hours work will not be and vice verse. currentCount = 1; newCount = 1; totalAmountNew = 0; totalAmountCurrent = 0; //insert budgets into HTML on load function initializeBudgetFields(currentProgram, newProgram) { if (currentProgram != '') { totalAmountCurrent = getPercentTotal(currentProgram); currentProgram = replace(currentProgram, ':', ' at ') currentProgram = replace(currentProgram, ';', '%<br>Acct #: ') currentProgram = 'Acct #: ' + currentProgram; currentProgram = currentProgram.substring(0, currentProgram.length-12); document.getElementById('budgets').innerHTML = currentProgram; currentCount = currentCount + 1; } if (newProgram != '') { totalAmountNew = getPercentTotal(newProgram); newProgram = replace(newProgram, ':', ' at ') newProgram = replace(newProgram, ';', '%<br>Acct #: ') newProgram = 'Acct #: ' + newProgram; newProgram = newProgram.substring(0, newProgram.length-12); document.getElementById('newBudgets').innerHTML = newProgram; newCount = newCount + 1; } } //gets the percent of all the budget codes added together, returns the amount function getPercentTotal(programStr) { continueBool=1; amount = 0; x=0; //makes sure it doesn't go forever while (continueBool!=0 && x < 8) { locEnd = programStr.indexOf(';'); tempStr = programStr.substring(0, locEnd); programStr = programStr.substring(locEnd+1, programStr.length); locEnd = tempStr.indexOf(':'); percent = tempStr.substring(locEnd+1, tempStr.length); amount = amount + parseFloat(percent); x=x+1; if (programStr.length <=0) continueBool=0; } return amount; } //add a budget code to the list function addBudgetCode(newCurrent) { // check the section to do it for if (newCurrent == 'current') { //make sure it is proper if (document.form.numberCurrentProgram.value != '') { if (isNumber(document.form.numberCurrentProgram.value) == 0) { document.form.numberCurrentProgram.focus(); return false; } if (document.form.numberCurrentProgram.value.length < 8) { document.form.numberCurrentProgram.focus(); alert('The current position budget code is incomplete, please use an 8 number budget code (without spaces).'); return false; } if (isFloat(document.form.percentCurrentProgram.value) == 0) { document.form.percentCurrentProgram.focus(); return false; } if (document.form.percentCurrentProgram.value <= 0 || document.form.percentCurrentProgram.value > 100) { alert('The current position percent budget code should be a number between 1 and 100.'); document.form.percentCurrentProgram.focus(); return false; } if (totalAmountCurrent + parseFloat(document.form.percentCurrentProgram.value) > 100) { alert('Budget codes cannot add to more than 100 percent. Revise the percent and try again.'); document.form.percentCurrentProgram.focus(); return false; } if (budgets.innerHTML == 'No budgets added.') budgets.innerHTML = ''; if (currentCount > 1) budgets.innerHTML = budgets.innerHTML + '<br>'; budgets.innerHTML = budgets.innerHTML + 'Acct #: ' + document.form.numberCurrentProgram.value + ' at ' + document.form.percentCurrentProgram.value + '%' currentCount = currentCount + 1; totalAmountCurrent = totalAmountCurrent + parseFloat(document.form.percentCurrentProgram.value); document.form.currentProgram.value = document.form.currentProgram.value + document.form.numberCurrentProgram.value + ':' + document.form.percentCurrentProgram.value + ';' document.form.numberCurrentProgram.value=''; document.form.percentCurrentProgram.value=''; disableSections(3); } } else { //make sure it is proper if (document.form.numberNewProgram.value != '') { if (isNumber(document.form.numberNewProgram.value) == 0) { document.form.numberNewProgram.focus(); return false; } if (document.form.numberNewProgram.value.length < 8) { document.form.numberNewProgram.focus(); alert('The new position budget code is incomplete, please use an 8 number budget code (without spaces).'); return false; } if (isFloat(document.form.percentNewProgram.value) == 0) { document.form.percentNewProgram.focus(); return false; } if (document.form.percentNewProgram.value <= 0 || document.form.percentNewProgram.value > 100) { alert('The new position percent budget code should be a number between 1 and 100.'); document.form.percentNewProgram.focus(); return false; } if (totalAmountNew + parseFloat(document.form.percentNewProgram.value) > 100) { alert('Budget codes cannot add to more than 100 percent. Revise the percent and try again.'); document.form.percentNewProgram.focus(); return false; } if (newBudgets.innerHTML == 'No budgets added.') newBudgets.innerHTML = ''; if (newCount > 1) newBudgets.innerHTML = newBudgets.innerHTML + '<br>'; newBudgets.innerHTML = newBudgets.innerHTML + 'Acct #: ' + document.form.numberNewProgram.value + ' at ' + document.form.percentNewProgram.value + '%' newCount = newCount + 1; totalAmountNew = totalAmountNew + parseFloat(document.form.percentNewProgram.value); document.form.newProgram.value = document.form.newProgram.value + document.form.numberNewProgram.value + ':' + document.form.percentNewProgram.value + ';' document.form.numberNewProgram.value=''; document.form.percentNewProgram.value=''; disableSections(3); } } } //clear the budget code list function clearBudgetCodes(newCurrent) { //check the section to do it for if (newCurrent == 'current') { budgets.innerHTML = 'No budgets added.' currentCount = 1; document.form.currentProgram.value = ''; document.form.numberCurrentProgram.value = ''; document.form.percentCurrentProgram.value = ''; totalAmountCurrent = 0; } else { newBudgets.innerHTML = 'No budgets added.' newCount = 1; document.form.newProgram.value = ''; document.form.numberNewProgram.value = ''; document.form.percentNewProgram.value = ''; totalAmountNew = 0; } disableSections(3); } i rewrote this code to implement the hours work but it was not working this is the code currentCount = 1; newCount = 1; totalAmountNew = 0; totalAmountCurrent = 0; //insert budgets into HTML on load function initializeBudgetFields(currentProgram, newProgram) { if (currentProgram != '') { totalAmountCurrent = getHoursTotal(currentProgram); totalAmountCurrent = getPercentTotal(currentProgram); currentProgram = replace(currentProgram, ':', ' at ') currentProgram = replace(currentProgram, ';', 'Hrs<br>Acct #: ') currentProgram = replace(currentProgram, ';', '%<br>Acct #: ') currentProgram = 'Acct #: ' + currentProgram; currentProgram = currentProgram.substring(0, currentProgram.length-12); document.getElementById('budgets').innerHTML = currentProgram; currentCount = currentCount + 1; } if (newProgram != '') { totalAmountNew = getHoursTotal(newProgram); totalAmountNew = getPercentTotal(newProgram); newProgram = replace(newProgram, ':', ' at ') newProgram = replace(newProgram, ';', 'Hrs<br>Acct #: ') newProgram = replace(newProgram, ';', '%<br>Acct #: ') newProgram = 'Acct #: ' + newProgram; newProgram = newProgram.substring(0, newProgram.length-12); document.getElementById('newBudgets').innerHTML = newProgram; newCount = newCount + 1; } } //gets the hours of all the budget codes added together, returns the amount function getHoursTotal(programStr) { continueBool=1; amount = 0; x=0; //makes sure it doesn't go forever while (continueBool!=0 && x < 8) { locEnd = programStr.indexOf(';'); tempStr = programStr.substring(0, locEnd); programStr = programStr.substring(locEnd+1, programStr.length); locEnd = tempStr.indexOf(':'); Hours = tempStr.substring(locEnd+1, tempStr.length); amount = amount + parseFloat(Hours); x=x+1; if (programStr.length <=0) continueBool=0; } return amount; } //gets the percent of all the budget codes added together, returns the amount function getPercentTotal(programStr) { continueBool=1; amount = 0; x=0; //makes sure it doesn't go forever while (continueBool!=0 && x < 8) { locEnd = programStr.indexOf(';'); tempStr = programStr.substring(0, locEnd); programStr = programStr.substring(locEnd+1, programStr.length); locEnd = tempStr.indexOf(':'); Percent = tempStr.substring(locEnd+1, tempStr.length); amount = amount + parseFloat(Percent); x=x+1; if (programStr.length <=0) continueBool=0; } return amount; } //add a budget code to the list function addBudgetCode(newCurrent) { // check the section to do it for if (newCurrent == 'current') { //make sure it is proper if (document.form.numberCurrentProgram.value != '') { if (isNumber(document.form.numberCurrentProgram.value) == 0) { document.form.numberCurrentProgram.focus(); return false; } if (document.form.numberCurrentProgram.value.length < 8) { document.form.numberCurrentProgram.focus(); alert('The current position budget code is incomplete, please use an 8 number budget code (without spaces).'); return false; } if (isFloat(document.form.HoursCurrentProgram.value) == 0) { document.form.HoursCurrentProgram.focus(); return false; } if (document.form.HoursCurrentProgram.value <= 0 || document.form.HoursCurrentProgram.value > 35) { alert('The current position percent budget code should be a number between 1 and 35.'); document.form.HoursCurrentProgram.focus(); return false; } if (totalAmountCurrent + parseFloat(document.form.HoursCurrentProgram.value) > 35) { alert('Budget codes cannot add to more than 35 percent. Revise the percent and try again.'); document.form.HoursCurrentProgram.focus(); return false; } if (budgets.innerHTML == 'No budgets added.') budgets.innerHTML = ''; if (currentCount > 1) budgets.innerHTML = budgets.innerHTML + '<br>'; budgets.innerHTML = budgets.innerHTML + 'Acct #: ' + document.form.numberCurrentProgram.value + ' at ' + document.form.HoursCurrentProgram.value + 'Hrs'+ document.form.PercentCurrentProgram.value + 'Hrs' currentCount = currentCount + 1; totalAmountCurrent = totalAmountCurrent + parseFloat(document.form.HoursCurrentProgram.value) + parseFloat(document.form.PercentCurrentProgram.value); document.form.currentProgram.value = document.form.currentProgram.value + document.form.numberCurrentProgram.value + ':' + document.form.HoursCurrentProgram.value + ':' + document.form.PercentCurrentProgram.value +';' document.form.numberCurrentProgram.value=''; document.form.HoursCurrentProgram.value=''; document.form.PercentCurrentProgram.value=''; disableSections(3); } } else { //make sure it is proper if (document.form.numberNewProgram.value != '') { if (isNumber(document.form.numberNewProgram.value) == 0) { document.form.numberNewProgram.focus(); return false; } if (document.form.numberNewProgram.value.length < 8) { document.form.numberNewProgram.focus(); alert('The new position budget code is incomplete, please use an 8 number budget code (without spaces).'); return false; } if (isFloat(document.form.HoursNewProgram.value) == 0) { document.form.HoursNewProgram.focus(); return false; } if (document.form.HoursNewProgram.value <= 0 || document.form.HoursNewProgram.value > 35) { alert('The new position Hours budget code should be a number between 1 and .'); document.form.HoursNewProgram.focus(); return false; } if (totalAmountNew + parseFloat(document.form.percentNewProgram.value) > 35) { alert('Budget codes cannot add to more than 35 hours. Revise the percent and try again.'); document.form.HoursNewProgram.focus(); return false; } if (newBudgets.innerHTML == 'No budgets added.') newBudgets.innerHTML = ''; if (newCount > 1) newBudgets.innerHTML = newBudgets.innerHTML + '<br>'; newBudgets.innerHTML = newBudgets.innerHTML + 'Acct #: ' + document.form.numberNewProgram.value + ' at ' + document.form.HoursNewProgram.value + 'Hrs' + document.form.percentNewProgram.value + '%' newCount = newCount + 1; totalAmountNew = totalAmountNew + parseFloat(document.form.HoursNewProgram.value) + parseFloat(document.form.percentNewProgram.value); document.form.newProgram.value = document.form.newProgram.value + document.form.numberNewProgram.value + ':' + document.form.percentNewProgram.value + ';' document.form.numberNewProgram.value=''; document.form.HoursNewProgram.value=''; document.form.percentNewProgram.value=''; disableSections(3); } } } //clear the budget code list function clearBudgetCodes(newCurrent) { //check the section to do it for if (newCurrent == 'current') { budgets.innerHTML = 'No budgets added.' currentCount = 1; document.form.currentProgram.value = ''; document.form.numberCurrentProgram.value = ''; document.form.HoursCurrentProgram.value = ''; document.form.percentCurrentProgram.value = ''; totalAmountCurrent = 0; } else { newBudgets.innerHTML = 'No budgets added.' newCount = 1; document.form.newProgram.value = ''; document.form.numberNewProgram.value = ''; document.form.HoursNewProgram.value = ''; document.form.percentNewProgram.value = ''; totalAmountNew = 0; } disableSections(3); } after i implemented this functions on my asp it was not working do anybody have the idea to implement these functions
This code is big man. May you put just the part of the code that is really needed to understand the problem? but I can spot something: in many places I see the following lines: totalAmountCurrent = getHoursTotal(currentProgram); totalAmountCurrent = getPercentTotal(currentProgram); Why do you do this?
this is the input screen on my classic asp. the code below is the old input screen for getpercentTotal </tr> <tr> <td class="unshadedSmall" valign="top" style="padding-top:7px"><label for="proposedInfo">Program/Budget Code: <br>(8-digit number)</label></td> <td class="unshadedSmall" valign="middle" nowrap> <input name="numberNewProgram" id="section3a_7" type="text" class="textbox1" size="6" maxlength="8"> at <input name="percentNewProgram" type="text" id="section3a_8" class="textbox1" value size="1" maxlength="4" style="text-align:center;">% <div id="button" onClick="addBudgetCode('new')">Add</div> <br>Budget/Split List <span onclick="clearBudgetCodes('new')"><u style="color:blue; cursorointer;">clear all</u></span><div id="newBudgets">No budgets added.</div> <input type="hidden" name="newProgram" value="<%=newProgram%>"> </td> and this is for the GetHoursTotal </tr> <tr> <td class="unshadedSmall" valign="top" style="padding-top:7px"><label for="proposedInfo">Program/Budget Code: <br>(8-digit number)</label></td> <td class="unshadedSmall" valign="middle" nowrap> <input name="numberNewProgram" id="section3a_7" type="text" class="textbox1" size="6" maxlength="8"> at <input name="HoursNewProgram" type="text" id="section3a_8a" class="textbox1" value size="1" maxlength="4" style="text-align:center;">Hrs <%if pv and accessLevel = ADMIN then%> <input name="percentNewProgram" type="text" id="section3a_8" class="textbox1" value size="1" maxlength="4" style="text-align:center;">% <%end if%> <div id="button" onClick="addBudgetCode('new')">Add</div> <br>Budget/Split List <span onclick="clearBudgetCodes('new')"><u style="color:blue; cursorointer;">clear all</u></span><div id="newBudgets">No budgets added.</div> <input type="hidden" name="newProgram" value="<%=newProgram%>"> </td>
Did you correct the following error: totalAmountCurrent = getHoursTotal(currentProgram); totalAmountCurrent = getPercentTotal(currentProgram); ??? you give to totalAmountCurrent 2 different values in your new initializeBudgetFields function. why?
Thanks for your quick responses, this was the initial codes that i wrote that was not working before trying to put the entire total percentage work and total hours worked calculated into the totatAmountCurrent and totalAmountNew and this wasn't working either. the purpose of this code was to do away with the percentage work splits and more to the Hours work splits but if the forms is to be loaded from the database it should retain the old data either way if it was previously entered as percentage or hour without converting it to hours work which is the new concepts. Thanks again currentCount = 1; newCount = 1; totalAmountNew = 0; totalAmountCurrent = 0; totalAmountNew1 = 0; totalAmountCurrent1 = 0; //insert budgets into HTML on load function initializeBudgetFields(currentProgram, newProgram) { if (currentProgram != '') { totalAmountCurrent1 = getHoursTotal(currentProgram); totalAmountCurrent = getPercentTotal(currentProgram); currentProgram = replace(currentProgram, ':', ' at ') currentProgram = replace(currentProgram, ';', 'Hrs<br>Acct #: ') currentProgram = replace(currentProgram, ';', '%<br>Acct #: ') currentProgram = 'Acct #: ' + currentProgram; currentProgram = currentProgram.substring(0, currentProgram.length-12); document.getElementById('budgets').innerHTML = currentProgram; currentCount = currentCount + 1; } if (newProgram != '') { totalAmountNew1 = getHoursTotal(newProgram); totalAmountNew = getPercentTotal(newProgram); newProgram = replace(newProgram, ':', ' at ') newProgram = replace(newProgram, ';', 'Hrs<br>Acct #: ') newProgram = replace(newProgram, ';', '%<br>Acct #: ') newProgram = 'Acct #: ' + newProgram; newProgram = newProgram.substring(0, newProgram.length-12); document.getElementById('newBudgets').innerHTML = newProgram; newCount = newCount + 1; } } //gets the hours of all the budget codes added together, returns the amount function getHoursTotal(programStr) { continueBool=1; amount = 0; x=0; //makes sure it doesn't go forever while (continueBool!=0 && x < 8) { locEnd = programStr.indexOf(';'); tempStr = programStr.substring(0, locEnd); programStr = programStr.substring(locEnd+1, programStr.length); locEnd = tempStr.indexOf(':'); Hours = tempStr.substring(locEnd+1, tempStr.length); amount = amount + parseFloat(Hours); x=x+1; if (programStr.length <=0) continueBool=0; } return amount; } //gets the percent of all the budget codes added together, returns the amount function getPercentTotal(programStr) { continueBool=1; amount = 0; x=0; //makes sure it doesn't go forever while (continueBool!=0 && x < 8) { locEnd = programStr.indexOf(';'); tempStr = programStr.substring(0, locEnd); programStr = programStr.substring(locEnd+1, programStr.length); locEnd = tempStr.indexOf(':'); Percent = tempStr.substring(locEnd+1, tempStr.length); amount = amount + parseFloat(Percent); x=x+1; if (programStr.length <=0) continueBool=0; } return amount; } //add a budget code to the list function addBudgetCode(newCurrent) { // check the section to do it for if (newCurrent == 'current') { //make sure it is proper if (document.form.numberCurrentProgram.value != '') { if (isNumber(document.form.numberCurrentProgram.value) == 0) { document.form.numberCurrentProgram.focus(); return false; } if (document.form.numberCurrentProgram.value.length < 8) { document.form.numberCurrentProgram.focus(); alert('The current position budget code is incomplete, please use an 8 number budget code (without spaces).'); return false; } if (isFloat(document.form.HoursCurrentProgram.value) == 0) { document.form.HoursCurrentProgram.focus(); return false; } if (document.form.HoursCurrentProgram.value <= 0 || document.form.HoursCurrentProgram.value > 35) { alert('The current position percent budget code should be a number between 1 and 35.'); document.form.HoursCurrentProgram.focus(); return false; } if (totalAmountCurrent + parseFloat(document.form.HoursCurrentProgram.value) > 35) { alert('Budget codes cannot add to more than 35 percent. Revise the percent and try again.'); document.form.HoursCurrentProgram.focus(); return false; } if (budgets.innerHTML == 'No budgets added.') budgets.innerHTML = ''; if (currentCount > 1) budgets.innerHTML = budgets.innerHTML + '<br>'; budgets.innerHTML = budgets.innerHTML + 'Acct #: ' + document.form.numberCurrentProgram.value + ' at ' + document.form.HoursCurrentProgram.value + 'Hrs'+ document.form.PercentCurrentProgram.value + 'Hrs' currentCount = currentCount + 1; totalAmountCurrent1 = totalAmountCurrent + parseFloat(document.form.HoursCurrentProgram.value); totalAmountCurrent = totalAmountCurrent + parseFloat(document.form.PercentCurrentProgram.value); document.form.currentProgram.value = document.form.currentProgram.value + document.form.numberCurrentProgram.value + ':' + document.form.HoursCurrentProgram.value + ':' + document.form.PercentCurrentProgram.value +';' document.form.numberCurrentProgram.value=''; document.form.HoursCurrentProgram.value=''; document.form.PercentCurrentProgram.value=''; disableSections(3); } } else { //make sure it is proper if (document.form.numberNewProgram.value != '') { if (isNumber(document.form.numberNewProgram.value) == 0) { document.form.numberNewProgram.focus(); return false; } if (document.form.numberNewProgram.value.length < 8) { document.form.numberNewProgram.focus(); alert('The new position budget code is incomplete, please use an 8 number budget code (without spaces).'); return false; } if (isFloat(document.form.HoursNewProgram.value) == 0) { document.form.HoursNewProgram.focus(); return false; } if (document.form.HoursNewProgram.value <= 0 || document.form.HoursNewProgram.value > 35) { alert('The new position Hours budget code should be a number between 1 and .'); document.form.HoursNewProgram.focus(); return false; } if (totalAmountNew + parseFloat(document.form.percentNewProgram.value) > 35) { alert('Budget codes cannot add to more than 35 hours. Revise the percent and try again.'); document.form.HoursNewProgram.focus(); return false; } if (newBudgets.innerHTML == 'No budgets added.') newBudgets.innerHTML = ''; if (newCount > 1) newBudgets.innerHTML = newBudgets.innerHTML + '<br>'; newBudgets.innerHTML = newBudgets.innerHTML + 'Acct #: ' + document.form.numberNewProgram.value + ' at ' + document.form.HoursNewProgram.value + 'Hrs' + document.form.percentNewProgram.value + '%' newCount = newCount + 1; totalAmountNew = totalAmountNew + parseFloat(document.form.percentNewProgram.value); totalAmountNew1 = totalAmountNew + parseFloat(document.form.HoursNewProgram.value); document.form.newProgram.value = document.form.newProgram.value + document.form.numberNewProgram.value + ':' + document.form.percentNewProgram.value + ';' document.form.numberNewProgram.value=''; document.form.HoursNewProgram.value=''; document.form.percentNewProgram.value=''; disableSections(3); } } } //clear the budget code list function clearBudgetCodes(newCurrent) { //check the section to do it for if (newCurrent == 'current') { budgets.innerHTML = 'No budgets added.' currentCount = 1; document.form.currentProgram.value = ''; document.form.numberCurrentProgram.value = ''; document.form.HoursCurrentProgram.value = ''; document.form.percentCurrentProgram.value = ''; totalAmountCurrent = 0; totalAmountCurrent1 = 0; } else { newBudgets.innerHTML = 'No budgets added.' newCount = 1; document.form.newProgram.value = ''; document.form.numberNewProgram.value = ''; document.form.HoursNewProgram.value = ''; document.form.percentNewProgram.value = ''; totalAmountNew = 0; totalAmountNew1 = 0; } disableSections(3); }