0

i can't figure out how to set a value using javascript.

Here is how the HTML look like:

<input type=​"text" name=​"cardholderName" data-bind=​"value:​ creditCardForm.name, 
css:​    creditCardForm.style.name" maxlength=​"30">​

When i try to set the value in the Chrome console

document.getElementsByName('cardholderName').value="myname";

The console returns "myname" but the field in the browser isn't populated with this approach. Any hints on what is missing? Thanks

1 Answer 1

2

getElementsByName returns an array, and there is no property value on an array. I think you mean to get the first item:

document.getElementsByName('cardholderName')[0].value="myname";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.