Bear Bibeault wrote:Any chance you could post an example without all the server-side markup? That all makes it impossible to load into a jsFiddle, or even a local file, and see what's going on.
Besides, the JavaScript "sees" what's sent to the browser, not the server-side code, and it's best to debug script issues (and CSS as well) by looking at what's sent to the browser.
The most likely thing that's going on is that the button press is not only triggering your script handler, but submitting the form. Just why is what is the question.
Bear Bibeault wrote:You can see what's actually being sent to the browser with a View Source or with the JavaScript debugger in the browser.
You can also set breakpoints in the JavaScript with the debugger.
My point is, trying to debug this on the server isn't going to make things very easy for you.
Bear Bibeault wrote:Another thought: you haven't put a type attribute on your button. Now, the default is supposed to be "button" which should not automatically submit the form, but it's not a bad practice to be explicit about it. There are some circumstances where a form will auto-submit implicitly (such as when there's one field and the user hits Enter).
Just to be safe, and complete, I'd go ahead and add type="button" to the button, even if it doesn't solve the problem.
James Whillis wrote:Oh! It works when I set type="button"
James Whillis wrote:
How to do it in Chrome? I can't find where to set breakpoints.
Bear Bibeault wrote:
James Whillis wrote:Oh! It works when I set type="button"
Aha. The browser is apparently defaulting the button to type submit.
This is why I'm always explicit and never omit the type attribute. I'll bet you'll be adding it to all buttons in the future as well! :cool:
Bear Bibeault wrote:Now's the time to put those debugging skills to work. Set a breakpoint in the handler. Does it get invoked? If so, step through the statements to see where it is going awry.
Hey, sticks and stones baby. And maybe a wee mention of my stuff:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|