Javascript/AngularJS/HTML How to call ng-submit from javascript from another program

292
April 17, 2017, at 09:19 AM

I have a website with this code. I need to know how I can call this form submit from within javascript that I am running on my machine. I can't seem to get this work. I fill out the username and password field just fine though.

<form name="loginForm" ng-submit="login()" autocomplete="off" class="ng-dirty ng-valid ng-valid-required">
<button type="submit" class="icon-login" ng-disabled="!loginForm.$valid"></button>
<input type="text" name="username" id="username" placeholder="Username / Email" autocapitalize="off" autocorrect="off" required="" ng-model="credentials.username" class="ng-dirty ng-valid ng-valid-required">
<input type="password" name="password" id="password" placeholder="Password" autocapitalize="off" autocorrect="off" required="" ng-model="credentials.password" class="ng-dirty ng-valid ng-valid-required">

I have tried the whole code below.. But that didn't seem to do it.

 document.getElementbyName(“loginForm”).dispatchEvent(new Event(‘submit’);
Answer 1

According to the docs for ng-submit, it "prevents the default action (which for form means sending the request to the server and reloading the current page), but only if the form does not contain action, data-action, or x-action attributes."

So I don't think you can submit the form. You could click your submit button though:

document.querySelectorAll("form[name='loginForm'] button.icon-login")[0].click()

READ ALSO
Compare with the next element in foreach javascript

Compare with the next element in foreach javascript

In my project I have to check for availability of time of a timetable, in a way to insert a button that should contains two values as textThe day starts at 8 and ends at 18, each day has its sessions

327
how to assign the data result of ajax response of cgridview custom button&#39;s click event to a php variable in yii 1.x?

how to assign the data result of ajax response of cgridview custom button's click event to a php variable in yii 1.x?

I have a custom button in CGridViewThere's a click event where by I have to pass the id of the row to the controller action in order to do a query

384
Not responsive tooltips

Not responsive tooltips

I found this beautiful template for help tooltips:

255
jQuery Sortable: element moves to top on drag

jQuery Sortable: element moves to top on drag

I'm using jQuery UI Sortable to drag and drop select menusI'm using MaterializeCSS as well for the style

369