3

I have a form as follows:

<form action="saveorderdetails.php" id="submitForm" name="formsubmit" method="post">
    <input type="hidden" id="ordertabledetailshidid" name="ordertabledetailshid">
    <input type="hidden" id="datedetailshidid" name="datedetailshid">
    <input type="hidden" id="customerdetailshidid" name="customerdetailshid">
</form>

and I have a div as follows: In that div I have a onclick() , which is used to submit the form.

<a href=""><div class="icon_boundary2" onclick="btn_save_click();"><i class="fa fa-check" style="font-size:20px;padding:4px 0px 5px 5px; color:#7298CD;"></div></a>

My javascript function as follows:

function btn_save_click(){
    document.getElementById("submitForm").submit();
}

But the page is not getting submitted. Instead it is reloading. I have tried all the alternatives like:

document.getElementById("submitForm").submit();

But none of them working!!

3
  • Make it a <button type="submit" form="formSubmit">. No js needed Commented Oct 19, 2015 at 9:02
  • @AI.G I did not want that, I know form submit will work. I need it in this way!! Commented Oct 19, 2015 at 9:03
  • Remove <a> tag and try again. Commented Oct 19, 2015 at 9:04

1 Answer 1

2

Just remove the anchor tag. This is how it should look like :

<div class="icon_boundary2" onclick="btn_save_click();"><i class="fa fa-check" style="font-size:20px;padding:4px 0px 5px 5px; color:#7298CD;"></div>
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks buddy it helped. But is there any way to do it with anchor tag also in it?
Why would you need an anchor tag with an empty href attribute?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.