Skip to content Skip to sidebar Skip to footer

How To Submit A Form Using Javascript

I'm trying to click on a submit button and submit a form using purely javascript. I have tried: document.getElementById('sell_form').submit(); and for(var i=0;i

Solution 1:

<script type="text/javascript">
  function callSubmit() {      
      document.forms[0].submit();
  }
</script>

<form id="sell_form" class="ajaxform" action="/member/sell" method="post">
    <div id="result" class="popup"> </div>  //hidden`enter code here`
    <div class="c-box-body">
        <table width="100%" border="0">
        <div style="text-align:center">
            <br>
            <input type="hidden" value="13" name="pair">    //hidden
            <input type="hidden" value="Sell" name="type">  //hidden
            <input type="submit" value="Calculate" name="calculate">
            <input type="submit" value="Sell" name="operation" onclick="callSubmit()">
            <input type="reset" value="Clear">
        </div>
    </div>
</form>

Solution 2:

I was able to to it with:

var element = document.querySelector('#sell_form input[name="operation"]');  
    if (element) {  
        element.click();
    }

Post a Comment for "How To Submit A Form Using Javascript"