Solved

How to run javascript code with HTML form button?

Posted on 2010-09-07
6
578 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
ID: 33619201
You can assign the onclick event to execute it?
<button onclick="addEvent()"'>
0
 
LVL 8

Accepted Solution

by:
pvlier earned 450 total points
ID: 33619206
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
ID: 33619221
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 33619489
type="button"

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

Author Closing Comment

by:ob1_
ID: 33619507
that was it, thanks!
0
 
LVL 8

Expert Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…

914 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

14 Experts available now in Live!

Get 1:1 Help Now