0

I have a form in AngularJS application. I need to auto submit this form upon page load without using jquery because of cross domain issue.

When I submit the form by using a submit button it works and the target url loads in the browser. If I remove the submit button and try to submit in the onload event, it does not work. The page displays just ";". Any idea why onload does not work here? Thank you!

<form name="myForm" method="post" action="@Model.Settings["URL"]" ng-controller="PostCtrl">
    <input type="hidden" name="Name" value="{{Details.Name}}">
    <input type="hidden" name="Amount" value="{{Details.Amount}}">

     @*<button type="submit" class="action blue"><span class="label">Click here</span></button>*@

    <script>
        window.onload = function () {
            document.myForm.submit();
        }
    </script>
</form>
1
  • you can submit the form in your angular controller instead. Commented Nov 28, 2017 at 21:48

1 Answer 1

1

I have some suggestions for you. But first you have to add an id to your form: 1: Go to your <html> element and call the onload function there --> <html onload="document.getElementById('yourform').submit();"> or 2: call the JavaScript function with php

<?php
echo "<script>document.getElementById('yourform').submit();</script>";
?>

Or 3: try to change your Script to

<script>
window.onload = function () {
            document.getElementById('yourform').submit();
        }
</script>
Sign up to request clarification or add additional context in comments.

Comments

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.