user4406224
user4406224

Reputation:

Get value from the input field and use it as a parameter in the function

I have a problem so I would value input from the input field as a parameter to put the delete function (insert in place X)

<input id="a" type="number" name="fname"><br>
<form action='#close' ng-controller='NoteFormController as formCtrl' ng-submit='formCtrl.delete(calCtrl.series[$index], X)'>
    <div class='form-field'>
        <input type='submit' value='delete value'>
    </div>
</form>

Thanks in advance for your help

Upvotes: 1

Views: 88

Answers (3)

Artem K.
Artem K.

Reputation: 804

Don't fallback to jQuery accessors. You should bind a scope variable to the input and access in the delete function or pass into the delete function.

<input id="a" type="number" name="fname" ng-model="someVariable"><br>
  <form action='#close' ng-controller='NoteFormController as formCtrl' ng-submit='formCtrl.delete(calCtrl.series[$index], someVariable)'>
        <div class='form-field'>
            <input type='submit' value='delete value'> 
        </div>

in your formCtrl controller, declare:

$scope.someVariable = '';

You can also access $scope.someVariable in the delete() function in the controller:

$scope.delete = function (seriesValue) {
    ...= $scope.someVariable;
}

Upvotes: 0

dfsq
dfsq

Reputation: 193301

You typically would need to use ngModel directive to bind value from input element to scope model. For example:

<input id="a" type="number" name="fname" ng-model="fname">
<br>
<form action='#close' 
      ng-controller='NoteFormController as formCtrl' 
      ng-submit='formCtrl.delete(calCtrl.series[$index], fname)'>
    <div class='form-field'>
        <input type='submit' value='delete value' />
    </div>
</form>

Note, above snippet assumes that you have outer controller that wraps input and form, so that fname model will be set in the parent scope relative to NoteFormController scope.

Upvotes: 1

indra444
indra444

Reputation: 51

try this ....

 $('#a').value();

Upvotes: 0

Related Questions