Connecting Tech Pros Worldwide Help | Site Map

Simple Web jsp question

Sl1ver's Avatar
Member
 
Join Date: Mar 2009
Location: Cape Town, South Africa
Posts: 102
#1: Sep 9 '09
say i add a textbox in html and a button, how do i assign functions to it

e.g. how will i write a piece of code that will know when the button has been pressed and will set a label to what was typed in the textbox?
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,629
#2: Sep 9 '09

re: Simple Web jsp question


standard way:

Expand|Select|Wrap|Line Numbers
  1. // say, the textbox has an id of "tb1"
  2. var tb = document.getElementById("tb1");
  3.  
  4. // type is e.g. "click", "change", …
  5. // your_function is the name of the function to be executed 
  6. //   without brackets or quotation marks
  7. tb.addEventListener(type, your_function, false);
the function your_function can now do anything necessary to set the label (or whatever). you may excessively use this.
Reply