By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,956 Members | 1,457 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,956 IT Pros & Developers. It's quick & easy.

unobtrusive javascript

P: 1
My code does not work , i cannot find what is wrong with it.
Please help me ! i don not want to use onclick in HTMl file to make unobtrusive javascript.

html

<form id="checkSudoku" action="#">
<input type="button" value="Check" id="check" />
</form>

javascript.

function check()
{
var check=document.getElementById('checkSudoku');
var checkbutton=check.getElementsByTagName('input');
for( var i=0; i < checkbutton.length; i++ ){
checkbutton[i].onclick=function(){
alert("hi");
}
}
May 13 '07 #1
Share this Question
Share on Google+
1 Reply


iam_clint
Expert 100+
P: 1,208
Expand|Select|Wrap|Line Numbers
  1.  
  2. <form id="checkSudoku" action="#">
  3. <input type="button" value="Check" id="check" />
  4. </form>
  5.  
  6. <script>
  7. window.onload = check();
  8. function check() {
  9. var check=document.getElementById('checkSudoku');
  10. var checkbutton=check.getElementsByTagName('input');
  11.  
  12. for(i=0;i < checkbutton.length;i++){
  13. checkbutton[i].onclick=function() { alert("hi"); }
  14. }
  15. }
  16. </script>
  17.  
works fine.... i think you were missing a closing } man :) good luck and if you need anything else just ask.
May 13 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.