Search code examples
javascripthtmlformsfallback

Submit form with anchor + javascript - bad practice?


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.


Solution

  • 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!