Wednesday, 19 August 2009

JS - Get object which called this method

Sample HTML + JS.

JS gets the tag which originally called the JS method. It can then read the value on the original 'input' tag

  function flipFormTarget(e) {
    document.getElementById('old-form').setAttribute('action', e.value);

<br><input type = 'radio'  value = 'top one' onclick="flipFormTarget(this)" checked>top option
<br><input type = 'radio'  value = 'bottom one' onclick="flipFormTarget(this)"> bottom

No comments:

Post a Comment