-5

I see from here that we can set value for the first element by document.getElementsByName('Contact0Email')[0].value = email; and second element by document.getElementsByName('Contact0Email')[1].value = email; and so on.

But how to set values for all the text fields with same name attribute?

2

2 Answers 2

0

I found it as:

var Firstname = document.getElementsByName("Firstname");
    for (var i=0; i < Firstname.length; i++) {
        Firstname[i].value = getAllUrlParams().Firstname;
    }

Javascript change fields value by name

Sign up to request clarification or add additional context in comments.

Comments

-1
document.querySelectorAll('.selector').forEach(
    function( element ) {
        element.value = '[email protected]';
    }
);

3 Comments

I want to select the text fields by name. Not class.
this applies to any css selector, ergo names are possible.
document.querySelectorAll('Contact0Email')

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.