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!!
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>
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
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?
but why have a button that submits when a submit button submits?
ASKER
that was it, thanks!
The second button doesn't need to submit if I understand correct, it needs to run the script...
<button onclick="addEvent()"'>