Tuesday, 15 July 2014

javascript - onChange function, summing values -



javascript - onChange function, summing values -

basically trying calculate input field value * hidden field value (this working). doing in 2 fields, both working. trying add together values together, stuck.....see code. appreciate help, give thanks in advance.

class="snippet-code-js lang-js prettyprint-override">function updatesum() { document.form.sum.value = (document.form.sum1.value - 0) * (document.form.sum2.value - 0); } function updatesum2() { document.form.sum5.value = (document.form.sum3.value - 0) * (document.form.sum4.value - 0); } function updatesum3() { document.form.sum6.value = (document.form.sum.value - 0) + (document.form.sum5.value - 0); } class="snippet-code-html lang-html prettyprint-override"> <form name="form"> number of adults: <input name="sum1" onchange="updatesum()" /> <input name="sum2" type="hidden" value="15" onchange="updatesum()" />total: <input name="sum" readonly style="border:0px;">number of adults: <input name="sum3" onchange="updatesum2()" /> <input name="sum4" type="hidden" value="15" onchange="updatesum2()" />total: <input name="sum5" readonly style="border:0px;">total2: <input name="sum6" readonly style="border:0px;"> </form>

you never called updatesum3() function. have onchange events updatesum() , updatesum2() functions. can phone call updatesum3() function both updatesum() , updatesum2() functions.

function updatesum() { document.form.sum.value = (document.form.sum1.value -0) * (document.form.sum2.value -0); updatesum3(); } function updatesum2() { document.form.sum5.value = (document.form.sum3.value -0) * (document.form.sum4.value -0); updatesum3(); }

javascript

No comments:

Post a Comment