views:

54

answers:

3

Dear Knowledge Base,

I currently have two anchor tags sending url queries to put votes inside a database, but i want to switch to using forms to keep the urls clean and avoid duplicate queries (not really an issue, but makes it look ugly).

Now the anchors need to contain a span-tag inside to add additional background elements to the buttons (links) through css, therefore I can't use regular form-buttons.

Do you consider submitting these forms from the anchors with javascipt as bad practice? I can think of some other solutions, but they all doesn't seem worth the trouble. Should I keep a no-script fallback where users with javascript disabled get to send url queries instead (i really want to avoid url queries altogether)? If, then how would this best be executed?

Thanks,
Simon.

+2  A: 

you can use <button> in your form. it can contain content, and you can style it as you like.

you can make it look exactly as the <a> you have now, but clicking it will submit a POST form. It is almost as if we have a <a> that does POST!

irreputable
Thank you, you learn something new every day :) i've heard ie6 and ie7 are having problems styling the padding (which is essential in my case) in input-buttons. is this the case even for button-elements?
cinnak
see IE box model bug. shouldn't be a problem if you declare proper DOCTYPE
irreputable
+3  A: 

Doing your buttons this way should work:

<button type="submit" value="upvote">
  <span>Vote Up</span>
</button>

<button type="submit" value="downvote">
  <span>Vote Down</span>
</button>

You should endeavor to never submit a form with JavaScript, or at the very least, ensure that the functionality is available when it is turned off.

Chris
Thank you - can't believe I didn't know about this!
cinnak
+1  A: 

I would recommend using the normal form submit button.
You can apply CSS to the button to make it look stylish or apply a background image.

I do not think the way you did it is a bad-practice. But the form will break for users who use add-ons like No-Script for Firefox.

Hrishi
There is wisdom in the above response. Noscript is kinda sneaky in that you never really know what you're missing out on unless you enable scripts for a site. It's good to make sure things degrade nicely without javascript.
virstulte
the problem is that i need additional background styling, therefore i needed to be able to have an extra tag inside the submit-element. but that was only an issue until i just found out about the button-element. Thanks though :)
cinnak