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

    Automation /

    Dart return Statement

    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

    ‹ Types of Asserts in TestNG framework› PivotTable and PivotChart

    Recent Posts

    • ChatGPT Plans Free and PlusChatGPT Subscription Plans
    • Stellar Converter for Database ToolStellar Converter for Database
    • Stellar MySQL Log AnalyzerStellar Log Analyzer for MySQL
    • Stellar Repair for MySQLStellar Repair for MySQL
    • ChatGPT IntroductionChatGPT Capabilities
    • How to secure your SQL Database: Tips and Tricks
    • ChatGPT4 Conversational AI FeaturesChatGPT4 Conversational AI Features
    • Trends in Software EngineeringShaping the Future of Development: Exploring Key Trends in Software Engineering
    • Java PerformanceImproving Java Performance with Multithreading
    • QDrant Vector DatabaseOpen-source Vector Databases
    • Difference between PHP and JavaScript?
    • Bing AI Browser Web ContentBing Conversation Styles
    • ChatGPT PreviewChatGPT Introduction
    • Open Source AI Frameworks TensorFlowOpen Source AI Frameworks
    • Artificial Intelligence Tools

    Back to Top

    Links

    • Contact
    • Privacy Policy
    • Cookie Policy

    www.TestingDocs.com