Document.getElementById not working

I have 2 chekboxes per page. Each of them is placed in a table cell in each row. Executing document.getElementById ('chk1_FEAS ~ 1005') returns the element, and document.getElementById ('chk5_STG2 ~ 1005') is NULL. For what reasons can this happen? (I am testing in IE 8).

<input id="chk1_FEAS~1005" value="JobStages###StageCode~JobCode###FEAS~1005" onclick="addRemoveRow(this.value,this.checked)" style="border-width:0px;padding:1px;margin:0px;height:14px;"  type="checkbox" />

<input id="chk5_STG2~1005" value="JobStages###StageCode~JobCode###STG2~1005" onclick="addRemoveRow(this.value,this.checked)" style="border-width:0px;padding:1px;margin:0px;height:14px;"  type="checkbox" />
+2
source share
4 answers

Your Identifier has invalid characters:

Identifier identifiers and NAME must begin with a letter ([A-Za-z]) and can be performed with any number of letters, numbers ([0-9]), hyphen ("-"), underscore ("_"), colons ( ":") and periods ("").

.

+10
document.getElementById('hk5_STG2~1005') 

document.getElementById('chk5_STG2~1005') 

: -)

+1

, , document.getElementById('chk5_STG2~1005')

In addition, I would recommend removing the ~ character, as it is not valid for the identifier.

0
source

For what it's worth, I have similar problems using document.getElementByIdon checkboxes in IE8. Try adding this tag to your section: -

<meta http-equiv="X-UA-Compatible" content="IE=7" />

This will make IE8 work in IE7 compatibility mode. This works for me as a workaround until I find out what it really is.

0
source

Source: https://habr.com/ru/post/1714988/


All Articles