Link to home
Create AccountLog in
Avatar of ob1_
ob1_

asked on

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

Avatar of pvlier
pvlier
Flag of Netherlands image

You can assign the onclick event to execute it?
<button onclick="addEvent()"'>
ASKER CERTIFIED SOLUTION
Avatar of pvlier
pvlier
Flag of Netherlands image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
SOLUTION
Avatar of Gurvinder Pal Singh
Gurvinder Pal Singh
Flag of India image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
type="button"

but why have a button that submits when a submit button submits?
Avatar of ob1_
ob1_

ASKER

that was it, thanks!
The second button doesn't need to submit if I understand correct, it needs to run the script...