Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


How to run javascript code with HTML form button?

Posted on 2010-09-07
Medium Priority
Last Modified: 2012-05-10
I have a web form with a submit button. I have created a new button on the form and put it next to submit. This button is called "Add User".

I have a javascript in the page that adds 2 rows to the form when the "Add User" javascript function is called.

This works fine if I link to the javascript using the <a href> HTML code below. how can I use the "Add User" form button to kick off the javascript rather than the <a href> code?

my form has method of "POST" and action "setup.asp".

would i have to put some code in setup.asp that says if button = submit then "submit form" if button = add user then "run java script" and return to page?

I know how to do this in php but not ASP.

please let me know if you need me to clarify anything. thanks!!
<a href="javascript:;" onclick="addEvent();">Add User</a></p>

Open in new window

Question by:ob1_
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 33619201
You can assign the onclick event to execute it?
<button onclick="addEvent()"'>

Accepted Solution

pvlier earned 1800 total points
ID: 33619206
Sorry.... really bad code.. here is try 2:
<input type="button" value="Add User" onclick="addEvent()">
LVL 40

Assisted Solution

by:Gurvinder Pal Singh
Gurvinder Pal Singh earned 200 total points
ID: 33619221
you can submit using javascript only

function submit()

call this function at the onclick event of the button you want

<input type='type' onclick='submit()'>
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

LVL 75

Expert Comment

by:Michel Plungjan
ID: 33619489

but why have a button that submits when a submit button submits?

Author Closing Comment

ID: 33619507
that was it, thanks!

Expert Comment

ID: 33619508
The second button doesn't need to submit if I understand correct, it needs to run the script...

Featured Post

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

660 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question