Information Technology, Tips and Tricks

Using Multiple “Submit” button in a single HTML Form without Javascript (For Mobile Browser)

When developing a web application, you might encounter a situation that you need to develop a single form with multiple submit button, and you want to know which submit button that user choose when submitting the form. As an example:

<input type=”submit” id=”submit” value = “ADD”>
<input type=”submit” id=”submit” value = “EDIT”>

How will you solve this problem?

For those who are familiar with JavaScript, it should not be a big deal, because most of the people will use JavaScript to solve this problem. Commonly, they will use onClick event attached to each submit button, so when the button get clicked, it will call a method that will assign certain value to the hidden field. In their backend, they just need to retrieve the value from this hidden field.

Well, using JavaScript will not give you any issue if you are developing a desktop web application. All desktop browser support JavaScript. The problem will only raise if your application will run on mobile browser? As we know, not all mobile browser support JavaScript .. specially old type, and more and more people are using their mobile browser now… so we need something that works across all the browser πŸ™‚

So how do we solve this problem? Here is another trick, that actually is very easy:

<input type=”submit” name=”submit” id=”submit” value = “ADD”>
<input type=”submit” name=”submit” id=”submit” value = “EDIT”>

and on your backend servlet

String whichButtonClicked = request.getParameter("submit");

The trick here is giving the attribute “name” on your submit button. According to the HTML Form specification, the “name/value” pair will be sent during form submission πŸ˜€

Happy trying πŸ˜€


2 thoughts on “Using Multiple “Submit” button in a single HTML Form without Javascript (For Mobile Browser)”

  1. whoah this blog is excellent i really like reading your articles. Stay up the good work! You already know, many persons are looking around for this info, you could help them greatly.


  2. Excellently written writeup, doubts all bloggers offered the same content material because you, the internet is actually a greater location. Please maintain it up!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s