[web] Buttons corrupt the address bar! Help!

Started by
2 comments, last by Sander 18 years, 10 months ago
I was using <input type="button" value="label" onclick="javascript:xxx" /> to launch &#106avascript events in my page. It struck me that a better idea would be <button onclick="javascript:xxx">label</button> since the inputs didn't really belong to a form, and the proper buttons can be CSS'd. There was one odd difference, though. When any button was clicked, now the address bar fills up with ?name=value&name=value... for all inputs on the page. Why should this happen and how do I stop it?
spraff.net: don't laugh, I'm still just starting...
Advertisement
Appearantly the browser is trying to submit a 'form', using a get-request.
I've tested it out, and it work fine in Explorer and FirefoxSo I have no idea what's going on.
But why not just use the input? Works in every browser and you can assign a css class to it or use the style attribute just fine.
Well, AFAIK inputs of type button can't contain other HTML such as images, and i'd have to type 'class="but"' or something for each of many buttons and I'd rather have a button{} entry in the .css.

It may well end up being the workable solution, but I'd still like to know why it's happening. They're not submit inputs.
spraff.net: don't laugh, I'm still just starting...
Do you have any form tags lingering around on your page? Buttons often become a default form submit widget. And else try:

<button onclick="javascript:xxx; return false;">Label</button>

<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>

This topic is closed to new replies.

Advertisement