Announcement Announcement Module
Collapse
No announcement yet.
submit button not calling javascript Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • submit button not calling javascript

    Hi,

    With html 5, I have a form with submit button. When I click the submit button, it doesn't involve its javascript.
    Here is my jsp file:
    Code:
    <form:form id="form" modelAttribute="vendorAttribute" method="POST" action="${saveUrl}">
                        <div class="success">Product form submitted!<br>
                        <strong>Haliluya.</strong> </div>
                        <fieldset>
                          <label class="name">
                            <form:input path="companyName" type="text" value="Company Name:" class="fleft"/>
                                  <span class="error error-empty">*This is not a valid name.</span><span class="empty error-empty">*This field is required.</span> </label>
                            <div class="clear"></div>
                          <label class="message">
                            <form:textarea path="note" value="Note:"/>
                            <span class="error">*Description is too short.</span> <span class="empty">*This field is required.</span> </label>
                        <div class="btns"><a data-type="reset" class="button-1" >Clear</a><a href="javascript: submitform()" data-type="submit" class="button-1" >Save</a></div>
                        </fieldset>
                    </form:form>
    
    <script type="text/javascript">
        function submitform() {
                      document.form.submit();
                    }
    </script>
    Any suggestion is very appreciated.
    Thanks
    Samuel

  • #2
    You don't have a button you have a a href ( a link) styled probably as a button. I wonder why not simply use a button but hijack a link (but that is just me).

    I suggest downloading and installing chrome (or firebug in FireFox) and see if there is something wrong with your javascript. Also if you have a javascript library that enhances (or does other things) to elements with data-* make sure the resulting DOM is valid.

    Comment


    • #3
      I changed href to onClick. Now the javascritp gets call (because alert pops up when I click the Save link, but the following "document.form.submit()" has no effect.
      Here is my javascript:

      Code:
      <script type="text/javascript">
          function submitform() {
                  alert("submit form")
                  document.form.submit();
                }
      </script>
      Any reason why document.form.submit() is failed? and how to change it?
      Thanls
      Samuel

      Comment

      Working...
      X