davej Posted September 27, 2013 Share Posted September 27, 2013 (edited) Maybe my system is infected with something? Somebody explain this... <!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><title>title</title><script>alert('page load');var cnt;window.onload = init; function init() { alert('init'); var c = document.getElementById("idbtn"); c.onclick = fncreate; cnt = 0;} function fncreate() { cnt++; alert('global cnt='+ cnt);}</script></head><body><form id="data1"><button id="idbtn">REBOOT</button></form><p><b>Just click the REBOOT button repeatedly</b></p></body></html> Edited September 27, 2013 by davej Link to comment Share on other sites More sharing options...
davej Posted September 27, 2013 Author Share Posted September 27, 2013 Maybe, because it is the only button, it just presumes that it is a submit button? Link to comment Share on other sites More sharing options...
Ingolme Posted September 27, 2013 Share Posted September 27, 2013 Yes, that's exactly what's happening. Use <button type="button"> to tell it that it's not meant to submit the form. Link to comment Share on other sites More sharing options...
davej Posted September 27, 2013 Author Share Posted September 27, 2013 (edited) Oh, I never use the button tag. I always use the input tag, but just to be different I thought I would use the button tag for a change. I figured the default would obviously be type=button. If I have to type button type=button each and every time then I don't see any point to ever using it. Edited September 28, 2013 by davej Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now