TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

Automation

Pass values to a JavaScript Function

Overview

In this post, we will develop a simple JavaScript function and learn how to pass values to a JavaScript function. The script is simple add function. However, we will pass the number of digits that needs to appear after decimal to the add function.

HTML Code

HTML Code

Enter the First number:  
Enter the Second number:  
  

www.TestingDocs.com | 2016

JavaScript Function

function add(decimaldigits) {
var aLocal = parseFloat(document.getElementById("a").value);
var bLocal = parseFloat(document.getElementById("b").value);
alert(aLocal);
var result = aLocal + bLocal;
resultStr = result.toFixed(decimaldigits) + "<br>";
document.getElementById("output").innerHTML = resultStr;
}

Sample Output

To run the JavaScript code, open the HTML file in the browser window.

Add the two numbers in the textboxes and hit on the Add button.

The output would be displayed in the output div element.

JavaScript Output

JavaScript tutorials on this website can be found at:
https://www.testingdocs.com/javascript-tutorial/

To learn more about JavaScript, visit

https://www.javascript.com/

Related Posts

Emma Tool

Automation /

Code Coverage Tools

Selenium 4 Automation Project

Automation /

Selenium 4 Project Setup on Ubuntu Linux

Testing webpage mobile-friendliness using a tool

Automation /

Testing webpage mobile-friendliness using a tool

Errors Code Testing Development

Automation /

Error Severity Metrics

Automation Environment Setup Verification

Automation /

Automation Environment Setup Verification

‹ Types of Asserts in TestNG framework› PivotTable and PivotChart

Recent Posts

  • MS Access Data Types
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com

Go to mobile version