Skip to content
Advertisement

Try GetElementsByClassName [closed]

try js ref_doc_getelementsbyClassName

“Uncaught TypeError: Cannot set property ‘value’ of null “

This HTML code

<input type="text" class="form-control" class="test"  />

This JS code

function inputtest() {
  document.getElementsByClassName('test').value = selectedControl;
}

Advertisement

Answer

Change your html:

<input type="text" class="form-control test"  />

JS

function inputtest() {
  document.getElementsByClassName('test')[0].value = selectedControl;
}
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement