Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 8th, 2012  |  syntax: None  |  size: 0.39 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How can I define a variable inside a function to be called by an event
  2. function testSet(elmA,elmB) {
  3.     elmA.onclick = function() {
  4.         elmB.value = "ok";
  5.     };
  6. }
  7.  
  8. testSet(document.getElementById('a'),document.getElementById('b'));
  9.        
  10. var globalElmB = something;
  11.  
  12. function testSet(elmA,elmB){
  13.     globalElmb = elmB;
  14.     elmA.onclick=function(){
  15.  
  16.         globalElmb.value="ok";
  17.     }
  18. }