thomasp423
thomasp423

Reputation: 367

Easiest way to store input into variables

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

Answers (2)

underscore
underscore

Reputation: 6887

Use;

   var value = parseInt($('#values').val(), 10);

DOC

Summary

The parseInt() function parses a string argument and returns an integer of the specified radix or base. Syntax

parseInt(string, radix);

Upvotes: 1

xdazz
xdazz

Reputation: 160953

You have to use .val() to get the value first.

// + used to cast string to number
var value = +$('#values').val();

Upvotes: 2

Related Questions