Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <h1>Find Percentage of a Number</h1>
- <ul>
- <li>
- <label for="base">Base:</label>
- <input type="text" id="base" />
- </li>
- <li>
- <label for="percent">Percent:</label>
- <input type="text" id="percent" />
- </li>
- <li>
- <p><span id="total">Total?</span></p>
- </li>
- <li>
- <input type="submit" id="submit" value="Calculate?" onclick="mainInit()" />
- </li>
- </ul>
- <script type="text/javascript">
- function mainInit() {
- if(document.getElementById) {
- if(document.getElementById("submit").onclick) {
- calculate();
- }
- }
- else {
- alert("Sorry, your browser does not support JavaScript.");
- }
- }
- function calculate() {
- var a = parseFloat(document.getElementById("base").value);
- var b = parseFloat(document.getElementById("percent").value);
- var total = document.getElementById("total");
- total.innerHTML = (a * (b/100)).toFixed(2);
- }
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement