javascript - Why does the browser change the value of the option in a element? -



javascript - Why does the browser change the value of the option in a <select> element? -

i have options generated in php. of values include html special chars &amp; or in case &oslash; (danish Ø).

for reason browser changes value of option, making hard compare same value passed simple compare function.

with alternative 1 selected ("&oslash;strig") , passing "&oslash;strig" below countryfilter function, homecoming false ??? , deugging can see e.value equal "Østrig" , not value set in html??

html:

<form> <select id='country' onchange='filter(false);'> <option value=''>* alle *</option> <option value='&oslash;strig'>&oslash;strig</option> <option value='argentina'>argentina</option> <option value='australien'>australien</option> ...

javascript:

function countryfilter(country) { var e = document.getelementbyid('country'); if (e.value=='') homecoming true; homecoming e.value.localecompare(country)==0; }

it makes sense displayed text translated & , Ø info in value alternative should remain untouched.

if alter options added dynamically in javascript iso php, works again, displayed value not translated :-/

1) why browser (tested both chrome , ie) mess data?

2) there way avoid this?

the content of value-attributes defined cdata(http://www.w3.org/tr/html401/interact/forms.html#adef-value-option).

for cdata documentation says:

cdata sequence of characters document character set , may include character entities. user agents should interpret attribute values follows:

replace character entities characters, ignore line feeds, replace each carriage homecoming or tab single space

that's browser does, replaces entities characters.

you may e.g. utilize Østrig comparison, or when want utilize string entities parse string before comparision:

function countryfilter(country){ var e = document.getelementbyid('country'), n = document.createelement('span'); n.innerhtml=country; if (e.value=='') homecoming true; homecoming e.value.localecompare(n.textcontent)==0; }

javascript php html

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -