Solved

How to run javascript code with HTML form button?

Posted on 2010-09-07
6
575 Views
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

0
Comment
Question by:ob1_
6 Comments
 
LVL 8

Expert Comment

by:pvlier
Comment Utility
You can assign the onclick event to execute it?
<button onclick="addEvent()"'>
0
 
LVL 8

Accepted Solution

by:
pvlier earned 450 total points
Comment Utility
Sorry.... really bad code.. here is try 2:
<input type="button" value="Add User" onclick="addEvent()">
0
 
LVL 40

Assisted Solution

by:gurvinder372
gurvinder372 earned 50 total points
Comment Utility
you can submit using javascript only

function submit()
{
    document.forms[0].submit();
}

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

<input type='type' onclick='submit()'>
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
type="button"

but why have a button that submits when a submit button submits?
0
 
LVL 6

Author Closing Comment

by:ob1_
Comment Utility
that was it, thanks!
0
 
LVL 8

Expert Comment

by:pvlier
Comment Utility
The second button doesn't need to submit if I understand correct, it needs to run the script...
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now