Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

JavaScript/HTML problem

  • 09-04-2013 12:22PM
    #1
    Closed Accounts Posts: 7


    Hello there,

    I have a problem in JavaScript/HTML. For example, there is two boxes, in one you enter 2 and in the other you enter the number 3. How would I make them multiply and show the answer in a textarea beneath the boxes.

    So, heres another example:

    Name: (enter name here)
    Price of water: (enter price)
    Lt. of water: (enter litres of water)

    Calculate (this is a button calling the function)

    ***This is where a textarea box is***

    So when the person enters the name, price and litres of water how would i get that results to appear in the textarea?


    Thanks in advance


Comments

  • Registered Users, Registered Users 2 Posts: 45,086 ✭✭✭✭Basq


    Sounds suspiciously like homework.

    Call a Javascript function akin to the following from the Calculate button:
    function calculate()
    {
       var nm = document.getElementById('name').value;
       var pr = document.getElementById('price').value;
       var li = document.getElementById('litres').value;
       
       document.getElementById('result').value = "Name: " + nm + "\r\nResult:" + (pr * li);
    }
    


  • Closed Accounts Posts: 7 hellomott0


    Basq wrote: »
    Sounds suspiciously like homework.

    Call a Javascript function akin to the following from the Calculate button:
    function calculate()
    {
       var nm = document.getElementById('name').value;
       var pr = document.getElementById('price').value;
       var li = document.getElementById('litres').value;
       
       document.getElementById('result').value = "Name: " + nm + "\r\nResult:" + (pr * li);
    }
    

    Thanks, eh it was homework a couple of months ago that I didn't do. Haha Now I just wanna learn it.

    thanks again


  • Registered Users, Registered Users 2 Posts: 45,086 ✭✭✭✭Basq


    hellomott0 wrote: »
    Thanks, eh it was homework a couple of months ago that I didn't do. Haha Now I just wanna learn it.

    thanks again
    No worries - that's very basic but a starting point..

    .. you'll need to do validation and the like yourself.


  • Closed Accounts Posts: 7 hellomott0


    Basq wrote: »
    No worries - that's very basic but a starting point..

    .. you'll need to do validation and the like yourself.

    :)


Advertisement