Select Option Value return Integer by default

Sruit A.Suk

Is it has any way to get value from Select Option as Integer by default ?

from select here

<select id="lesson_per_class" >
 <option value="">&nbsp;</option>
 <option value="1">1 Lesson</option>
 <option value="2">2 Lessons</option>
 <option value="3">3 Lessons</option>
 <option value="4">4 Lessons</option>
</select>

When I tried to get their value to calculate, I found that it return as String and can't use to calculate here

var lesson_per_class = $('#lesson_per_class').val();
alert('value is ' + ( 10 + lesson_per_class )); 
// it give result as 10x instead of 1x 

currently, the way I solved is parseInt(), but I need to know, is it has anyway to get it as Integer by default?

mccainz

From the spec you can see the value is a DOMString so no, you cannot get an integer by default.

http://www.w3.org/TR/html5/forms.html#the-option-element

For Java and ECMAScript, DOMString is bound to the String type because both languages also use UTF-16 as their encoding.

[NamedConstructor=Option(optional DOMString text = "", optional DOMString value, optional boolean defaultSelected = false, optional boolean selected = false)]
interface HTMLOptionElement : HTMLElement {
           attribute boolean disabled;
  readonly attribute HTMLFormElement? form;
           attribute DOMString label;
           attribute boolean defaultSelected;
           attribute boolean selected;
           attribute DOMString value;

           attribute DOMString text;
  readonly attribute long index;
};

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Select Option Value return Integer by default

From Dev

Set default value of select to null option

From Dev

Codeigniter in select option default value not working

From Dev

how to set a default value for select option

From Dev

Default Select Option Based on Input Value

From Dev

Skip select option if default value come

From Dev

The default value is not ? object:null ? in select option Angularjs

From Dev

Default value to select option menu is not recognized

From Dev

Return and refresh select option value on closest tr

From Dev

CakePHP2 - Default value for input - select with option multiple

From Java

how to use ng-option to set default value of select element

From Dev

Make the default option of select tag to be of current value of name in Rails

From Dev

set default option in a select via ng-init on VALUE and not INDEX

From Dev

Unable to get value of default option in select2 jquery

From Dev

AngularJS - ng-repeat default value for select option

From Java

default select option as blank

From Dev

HTML <select> default option

From Dev

default setting for option select

From Dev

default value in option

From Dev

AngularJS select creates option with value "? object:null ?" and doesn't use empty default option when bound to null

From Dev

KSH return value is not integer

From Dev

Laravel - Select - set Default option

From Dev

Laravel Option Select - Default Issue

From Dev

Laravel Option Select - Default Issue

From Dev

add default option to angularjs select

From Dev

change color of default option in select

From Dev

Jquery select option default option text

From Dev

Select option by value jquery

From Dev

is a select option with no value, valid?

Related Related

HotTag

Archive