Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Weird Javascript - Not working out correct percentage

Featured Replies

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" :blink:

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>

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

  • 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 by Marvedia

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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.