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 Help???

  • 02-09-2010 05:56PM
    #1
    Registered Users, Registered Users 2 Posts: 263 ✭✭


    Hi guys, I have 2 input labels in a form and i wanna be able to do some calculation and output to another label, without the user having to do more than input details into the 2 input boxs... No buttons to click if you know what i mean... I know how to do this in vb, but am unsure if ya can do it in javascript... Can someone help please?

    Any information much appreciated


Comments

  • Closed Accounts Posts: 7,144 ✭✭✭DonkeyStyle \o/


    Attach some events to the text inputs, onkeyup and/or onchange should do it... or there's more here that might suit depending on what form inputs you're using.
    Basically have those events call your function which reads the field's values every time.
    Then use .innerHTML or whatever to output the result.

    Rough example...
    <head>
    function doSomething()
    {
      var something1 = document.getElementById('field1').value;
      var something2 = document.getElementById('field2').value;
    
      // do whatever
    
      document.getElementById('result').innerHTML = "The answer is " + answer;
    }
    
    <body>
    <input type="text" id="field1" onkeyup="doSomething()">
    <input type="text" id="field2" onkeyup="doSomething()">
    <span id="result"></span>
    


Advertisement