0

I'm trying to output my radio button option to my HTML page for example if the user selects Humber current project it should show "Humber news project" but in my case, it says "undefined project"

<p id="caption_project">Project Selection
            <br/>
            <input type="radio" name="f__project" id="in_restaurant" value="restaurant"/>
            <label for="in_restaurant">LEGO Project</label>
            <br/>

            <input type="radio" name="f__project" id="in_humber" value="Humber News"/>
            <label for="in_humber">Humber Current Project</label>
            <br/>

            <input type="radio" name="f__project" id="in_self" value="self-determined"/>
            <label for="in_self">Self-determined Project</label>
            </p>

   option of the <span id="result__project"></span> project.
var userProject = document.getElementsByName("f__project");
var outputUserProject = document.getElementById("result__project");


outputUserProject.innerHTML = userProject.value;

Is there a reason why it say undefined project?

  • None of your elements have `id="result__project"` – Dai Nov 18 '22 at 01:32
  • `getElementsByName` returns a _collection_ of elements, not a single element - that's why `userProject.value` doesn't work for you. You need to dereference _some specific member_ of the collection using the indexer first. – Dai Nov 18 '22 at 01:32
  • @Dai my bad I edit now. it should show at the bottom of the HTML code. – Danyal Chatha Nov 18 '22 at 01:33

0 Answers0