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


<html>
<head>
<script>
  function flipFormTarget(e) {
    alert(e.value)
    document.getElementById('old-form').setAttribute('action', e.value);

  }
</script>
</head>
<body>
<br><input type = 'radio'  value = 'top one' onclick="flipFormTarget(this)" checked>top option
<br><input type = 'radio'  value = 'bottom one' onclick="flipFormTarget(this)"> bottom
</body>
</html>

No comments:

Post a Comment