Streaming live at 10am (PST)

Calculator coding


#1

this is a code I have for a Wh to mAh calculator, works great exactly how I want it but it's blocking all the other elements on my webflow page please help!!1

Convert Watt hours to mAh
  <div>
    <span>Insert Watts-hour (Wh) and voltage (V) and click on Calculate to obtain milliamp-hours (mAh).</span>
  </div>
  <div>
    <div class="divinput">
      <input id="watts2" name="Wh" size="8"> <span class="units">Wh</span>
    </div>
    <div class="divinput">
      <input id="volts2" name="V" size="8"> <span class="units">V</span>
    </div>
    <div class="divinput">
      <input onclick="convert2()" type="submit" value="Calculate">
    </div>
    <div class="divinput">
      <input id="mAh2" name="mAh" size="8"> <span class="units">mAh</span>
    </div>
  </div>
  <div>
    <span>1 kilowatt hour = 1000 watt hour, therefore the formula is (Wh)*1000/(V) =(mAh).</span> <span>For example, if you have a 1.5Wh battery rated at 5V, the power is 1.5Wh * 1000 / 5V = 300mAh. The battery rating will determine how many batteries are needed once the mAh is calculated.</span>
  </div>

function convert() {
  a = document.getElementById("mAh").value, 
  b = document.getElementById("volts").value, 
  c = a * b / 1e3, 
  document.getElementById("watts").value = c
}

function convert2() {
  a = document.getElementById("watts2").value, 
  b = document.getElementById("volts2").value, 
  c = 1e3 * a / b, 
  document.getElementById("mAh2").value = c
}

#2

Your question is very unclear. How is it blocking all the other elements on your Webflow page?


#3

I've updated the original post as user pasted in html which was simply converted by forum directly to text only :slight_smile:

@Tanya_Chin can you link us to the Webflow project where you are using this code? We'd like to help, but we don't know what you exactly meant :frowning:


Btw, you can't add onClick attribute, so you can do that either with Embed function https://help.webflow.com/article/how-to-use-the-embed-widget-to-add-custom-code-to-a-webpage or use some jQuery

$('input[type=submit].divinput').click(function () { ... });

here to run this onClick.


#4

Thank you, i was able to finally fix the bug in the code and get it fixed, really appreciate the feedback :slight_smile:


#5

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.