Skip to content Skip to sidebar Skip to footer

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 rea

Solution 1:

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!

Solution 2:

Doing your buttons this way should work:

<buttontype="submit"value="upvote"><span>Vote Up</span></button><buttontype="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.

Solution 3:

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.

Post a Comment for "Submit Form With Anchor + Javascript - Bad Practice?"