38

I have the following inputs and need their values:

<input type="hidden" ng-model="movie" value="harry_potter"/>
<input type="text" ng-model="year" value="2000"/>

What can I do to get the value of each input?

1
  • 2
    provide your controller code Commented Jan 10, 2014 at 9:34

2 Answers 2

31

If you want to get values in Javascript on frontend, you can use the native way to do it by using :

document.getElementsByName("movie")[0].value;

Where "movie" is the name of your input <input type="text" name="movie">

If you want to get it on angular.js controller, you can use;

$scope.movie
Sign up to request clarification or add additional context in comments.

3 Comments

There is no document.getElementByName() function. You're missing an 's' in the function name, and that function returns an array, so it would be document.getElementsByName("movie")[0].value (assuming you only have 1 element with that name).
Can we get a valid answer here that is actually best practice? $scope.movie / similiar $scope accessing does not work
I get property value does not exist on NodelistOf<HTMLElement>.
4

If your markup is bound to a controller, directive or anything else with a $scope:

console.log($scope.movie);

6 Comments

I tried to do this way but I got "undefined"
Yeah me too. What is the deal with this?
@light24bulbs exactly i m also facing undefined ? what is the issue
Someone? anyone? can we please get some answers here
stackoverflow.com/questions/31988632/… you have to use object.property notation (in your case for instance $scope.movie.title)
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.