September 16, 201114 yr Hi all. I've got a weird little javascript issue here that's confusing the hell out of me. My maths can't be so bad that I can't work out a simple percentage! Box 1 is calls offered, box 2 is calls answered. All I want box 3 to do is show the call answer rate, so (box 1 / box 2) * 100 = box 3. I put 100 in the first box, 95 in the second, which should mean the last box outputs 95%. BUT... I get "105.26315789473683" Here's the .js file running the script: function startCalc(){ interval = setInterval("perc()",1); } function perc() { a = document.evening_summary_form.existing_offered.value; b = document.evening_summary_form.existing_answered.value; c = a/b; d = c*100; document.evening_summary_form.existing_answer_rate.value = d } function stopCalc(){ clearInterval(interval); } And here's the section of the form it relates to: <td align="center" class=""> <label> <input name="existing_offered" type="text" id="existing_offered" size="4" onFocus="startCalc();" onBlur="stopCalc();"/> </label></td> <td align="center"> <label> <input name="existing_answered" type="text" id="existing_answered" size="4" onFocus="startCalc();" onBlur="stopCalc();"/> </label></td> <td align="center"> <label> <input name="existing_answer_rate" type="text" id="existing_answer_rate" size="3" readonly="readonly" />% </label></td>
September 16, 201114 yr Try this instead (box 2 / box 1) * 100 = box 3. At present it is 100 divided by 95, times 100 = 1.052631578947368 You need 95 divided by 100, times 100 = 95
September 16, 201114 yr Author Yeah I'm a dumbass!! I tried that twice but wasnt checking the file back in. It's working now... I knew I couldn't be that stupid, but clearly I am haha Schoolboy.... Edited September 16, 201114 yr by Marvedia
September 16, 201114 yr Yeah I'm a dumbass!! I tried that twice but wasnt checking the file back in. It's working now... I knew I couldn't be that stupid, but clearly I am haha Schoolboy.... It's easy enough to do. Sometimes we get caught up in the minutiae and miss the obvious.
Create an account or sign in to comment