Hyphen in div id causing javascript error

I am having a problem with javascript, as a result of which I am doing the following to close the popup and update the field in the parent window with the desired value. The code looks something like this:

<script language="javascript" type="text/javascript">
    var FieldID = document.form.field22-1.value;
    self.parent.opener.document.+FieldID = 'some text';
    window.top.window.close();
</script>

However, I get the following error:

Error: missing ; before statement

I find it funny that javascript interprets the field identifier (field22-1) as having a subtraction. Which, I think, would make sense. Any ideas / help would be ridiculously appreciated, really do not want to come back and change the code - in the code!

Thanks in advance!

+3
source share
4 answers

Use document.getElementById('field22-1').valueinstead.

You may also need to fix this:

self.parent.opener.document[FieldID] = 'some text';
+6
source

JavaScript , . foo.bar , . foo["bar"]. , ( ):

var FieldID = document.form["field22-1"].value;

, id, :

var FieldID = document.getElementById('field22-1').value;
+3

You can also use document.form['field22-1'].value.

+2
source

you can use document.getElementById('field22-1').value

+1
source

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


All Articles