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

Options
  • 02-09-2010 5:56pm
    #1
    Registered Users 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,145 ✭✭✭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