Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make form run a javascript function?

How can I make my form run a function when submit is clicked?

<form id="commentForm" name="comment">
    <fieldset>
        <label for="name">Name <span>(required)</span></label>
        <input type="text" class="text" id="name" value="" />
        <label for="email">Email <span>(will not be published) (required)</span></label>
        <input type="text" class="text" id="email" value="" />
        <label for="website">Website</label>
        <input type="text" class="text" id="website" value="" />
        <label for="message">Message <span>(required)</span></label>
        <textarea id="message" class="textarea" rows="10"></textarea>
        <input type="submit" name="submit" class="submit" id="submit_btn" value="Submit Comment" action="JavaScript: ajax_add_comment();">
    </fieldset>
    ...

I am trying running the following function:

function ajax_add_comment () {
    alert ("testing");
}
like image 634
Mark Topper Avatar asked Mar 16 '26 00:03

Mark Topper


1 Answers

Use onclick attribute instead of action.

like image 81
Dmytro Zarezenko Avatar answered Mar 17 '26 12:03

Dmytro Zarezenko