www.webdeveloper.com
Results 1 to 4 of 4

Thread: How to Input Data

Hybrid View

  1. #1
    Join Date
    Sep 2012
    Location
    Dhaka
    Posts
    2

    How to Input Data

    I am going to ask you a childish question about JavaScript. I asked you this question because I am beginner in JavaScript. I hope you will give me solution.
    Code:
    <!DOCTYPE html>
    <html>
    <body>
    
    <p>Click the button to calculate x.</p>
    <button onclick="myFunction()">Try it</button>
    
    <p id="demo"></p>
    
    <script>
    function myFunction()
    {
    y=5;
    z=2;
    x=y+z;
    document.getElementById("demo").innerHTML=x;
    }
    </script>
    
    </body>
    </html>
    When I place the above code, it will show me following result:
    Untitled.png

    If I press button "try it" it will show me a result 7.

    Now I want to know that how can I input different values of y and z and get value of x by using javascript code?

    Please give me an example.

  2. #2
    Join Date
    Mar 2009
    Posts
    452


    just change the values in your code like
    y=56;
    z=25;
    or you can use an HTML from with two text fields, for more about how to use from with javascript search google.

  3. #3
    Join Date
    Sep 2012
    Posts
    3
    try this code you can input any values you want

    Code:
    <!DOCTYPE html>
    <html>
    <body>
    
    	<p>
    	first value :<input type="text" name="y" size="20"><br>
    	second value:<input type="text" name="z" size="20">
    	</p>
    
    <p>Click the button to calculate x.</p>
    <button onclick="myFunction()">Try it</button>
    
    <p id="demo"></p>
    
    <script>
    function myFunction()
    {
    
    x=parseFloat(y.value)+parseFloat(z.value);
    document.getElementById("demo").innerHTML=x;
    }
    </script>
    
    </body>
    </html>

  4. #4
    Join Date
    Sep 2012
    Location
    Dhaka
    Posts
    2
    Quote Originally Posted by codingforever99 View Post
    try this code you can input any values you want

    Code:
    <!DOCTYPE html>
    <html>
    <body>
    	<p>
    	first value :<input type="text" name="y" size="20"><br>
    	second value:<input type="text" name="z" size="20">
    	</p>
    
    <p>Click the button to calculate x.</p>
    <button onclick="myFunction()">Try it</button>
    
    <p id="demo"></p>
    
    <script>
    function myFunction()
    {
    
    x=parseFloat(y.value)+parseFloat(z.value);
    document.getElementById("demo").innerHTML=x;
    }
    </script>
    
    </body>
    </html>
    I have tried your code but it is not working. I have input the values of Y and Z and click on the button "try it" but it did not show me any result. I think there is something more.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles