form value fill using javascript

44 views Asked by At

i am filling this value using javascript code. after that i am able to see this value in cosole. but value not visible in box. due to this i am unable to click submit button.this element is in a form tag.images link https://i.stack.imgur.com/quZ8f.png https://i.stack.imgur.com/r9KgX.jpg

function myfn(){
  document.getElementsByName("ELEC_CURR_B_PHASE").value="415V";
  var x= document.getElementsByName("ELEC_CURR_B_PHASE").value="415V";
  console.log(x);

};myfn()

result after running code
inspect element image

1

There are 1 answers

1
Khalil On BEST ANSWER

getElementsByName() returns a NodeList and to set the property value, select the first index.

function myfn(){
  document.getElementsByName("ELEC_CURR_B_PHASE").value="415V";
  var x= document.getElementsByName("ELEC_CURR_B_PHASE")[0].value="415V";
  console.log(x);
};
myfn();