Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8478611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:47:35+00:00 2026-06-10T18:47:35+00:00

I have various forms on a page, and a PHP-generated select on the top

  • 0

I have various forms on a page, and a PHP-generated select on the top of the page.

What I want to do is:

  • The user selects an option from the form.
  • The value of the option is put into all of the inputs with a specific name.
  • The user can select another option, and the value of that option would replace the old value of the input.

The code I have so far (that doesn’t work):
It doesn’t work as in the onChange only fires the first time you select an option, and the values of the inputs aren’t updated to the chosen option’s value.

The select: (It can have more or less than three options, depending on the user.)

<select name="example" onchange="setexample()" id="exampleID">
<option value="1">Default Example</option>
<option value="12">User-created Example #2</option>
<option value="8">User-created Example #1</option>
</select>

This is part of one of the forms around the page:

<form action="[URL]" method="get">
<input type="hidden" name="exampleform" id="example1" value="">
// Other inputs //
</form>

JavaScript:

<script>
function setexample(){
setexample = document.getElementById("exampleID").options[document.getElementById("exampleID").selectedIndex].value;
document.getElementsByName("exampleform").value = setexample;
}
</script>

I don’t want to use jQuery. This is just JavaScript.

Thank you in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T18:47:37+00:00Added an answer on June 10, 2026 at 6:47 pm

    The getElementsByName() method returns a list of elements, so you can’t just directly set the value property that belongs to the individual elements in the list. You need to loop through the list (it’s an HTMLCollection but for this purpose you can treat it like an array):

    var els = document.getElementsByName("exampleform");
    for(var i = 0; i < els.length; i++)
        els[i].value = setexample;
    

    For the rest, see RobG’s answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have am HTML form in a PHP page. The form has various inputs.
I have a PHP page with various forms I've been using jQuery to submit/verify
Say we have a form where the user types in various info. We validate
I am submitting from a form to another php page which is supposed to
I have an html page where the user is asked to enter in various
I have 1 page that displays a form with various dropdowns that are being
I have a page with three simple html forms which submit to various tables
I have an account registration form where a user can select their account type.
We have a C# win Form app called Installer that silently installs various 3rd
Javascript I have code that will hide various sections in a MS CRM form

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.