Home » Tutorial

Use Button Instead of Submit for Form

Written By: techieDan on January 18, 2009 One Comment

For those in the programming area, if you’re doing simple form processing of your HTML, why some people prefer buttons over submit.

Well for my personal preference, one of the good thing is that I can disable the automatic enter key that people tend to associate with forms. Well, it’s good at the same time, but it’s also sometimes good that you can limit your users from using the Enter key to submit the form if you want to do something else with it.

Getting a bit confusing, well, what is important is that by using buttons, I can forced the user to enable javascript in order to submit. Here’s how I do it.

<form name="form1" method="post" action="somepage" >
<input type='text' name='name' />
<input type='button' value='Submit This Name' 
onClick='submitForm(this.form1);'>
</form>

Now if the user disables javascript, they won’t be able to process the form unless they are smart enough to change it, which most programmers and IT techies know. But this is just a small deterrent. Here’s the javascript part.

<script language="javascript">
function submitForm(thisform) {
thisform.submit();
}
</script>

There are lots of ways out there to force javascript control to be enabled on the form. But this is just the simplest of it all.

Related Posts with Thumbnails

Tags: ,

Digg this!Add to del.icio.us!Stumble this!Add to Techorati!Share on Facebook!Seed Newsvine!Reddit!Add to Yahoo!

One Response to “Use Button Instead of Submit for Form”

  1. Lasker says on: 18 January 2009 at 1:37 am

    Don’t worry, disabling javascript is very very rare for regular user. In fact, if they do, they must already be IT savvy :D

Trackbacks/Pingbacks

  1. Javascript Submit Form Not Working | TechieDan

Leave a Reply:

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

  Copyright © 2009 TechieDan, All rights reserved.| Powered by WordPress