Option value change of the select element

Asked

Viewed 68 times

2

I’m trying to add an option to a select:

function add(){
    var opt = document.createElement("option");
    opt.value = "0101";
    opt.text = "foo";
}

That code works.

My question is why when I remove double quotes from the line where I pass the value to the option the value of it becomes 65 ?

  • 1

    I know it doesn’t answer the question, but Forms values are always strings, so they should be set in quotes anyway.

  • I agree with you in parts, because if this code were written directly html you would be right, but this is being done in javascript.

1 answer

2


@Felippetadeu Javascript starts to do bit Manipulation when it finds the value 0101 (which in ascii 8bit is equal to decimal 65);

When the numbers/values you want to assign to a variable nay are integer, or decimal (1.2, Pex), it is appropriate for such values between skins.

I agree with you in parts, because if this code were written directly in html you would be right, but this is being done in javascript. - Felippe Tadeu

This is right up to a point, as you can see in your code.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.