Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

JavaScript/HTML problem

Options
  • 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 Posts: 43,877 ✭✭✭✭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 Posts: 43,877 ✭✭✭✭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