How to run javascript code with HTML form button?

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

Who is Participating?
pvlierConnect With a Mentor Commented:
Sorry.... really bad code.. here is try 2:
<input type="button" value="Add User" onclick="addEvent()">
You can assign the onclick event to execute it?
<button onclick="addEvent()"'>
Gurvinder Pal SinghConnect With a Mentor Commented:
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()'>
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

Michel PlungjanIT ExpertCommented:

but why have a button that submits when a submit button submits?
ob1_Author Commented:
that was it, thanks!
The second button doesn't need to submit if I understand correct, it needs to run the script...
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.