Skip to content

Instantly share code, notes, and snippets.

@s4nchez
Created August 11, 2011 15:22
Show Gist options
  • Save s4nchez/1139926 to your computer and use it in GitHub Desktop.
Save s4nchez/1139926 to your computer and use it in GitHub Desktop.
Basic JavaScript skills test
<html>
<head></head>
<body>
<input name="myButton" type="button" value="button 1">
<input name="myButton" type="button" value="button 2">
<input name="myButton" type="button" value="button 3">
<script type="text/javascript">
var buttons = document.getElementsByName("myButton");
for(var i = 0; i < buttons.length; i++){
buttons[i].onclick = function(){
window.alert("clicked button " + (i + 1));
};
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment