Reputation: 367
I've got a simple form with options. I know there is a better way to store and parse the string to store it as a number.
<html>
<select id="values">
<option value="1"></option>
</select>
</html>
js:
var value = $('#values').parseInt(10);
Upvotes: 0
Views: 49
Reputation: 6887
Use;
var value = parseInt($('#values').val(), 10);
Summary
The parseInt() function parses a string argument and returns an integer of the specified radix or base. Syntax
parseInt(string, radix);
Upvotes: 1
Reputation: 160953
You have to use .val()
to get the value first.
// + used to cast string to number
var value = +$('#values').val();
Upvotes: 2