---
title: "How to get a selected value from the group of elements with the same name?"  
description: "How to get a selected value from the group of elements with the same name?"  
author: "Revati S Misra"  
published: 2023-08-29  
updated: 2023-09-02  
canonical: https://www.mindstick.com/forum/159728/how-to-get-a-selected-value-from-the-group-of-elements-with-the-same-name  
category: "html"  
tags: ["jquery selectors", "jquery validate", "html element"]  
reading_time: 1 minute  

---

# How to get a selected value from the group of elements with the same name?

How to get a [selected value](https://www.mindstick.com/forum/525/get-selected-value-of-datagridviewcomboboxcolumn) from the [group](https://yourviews.mindstick.com/view/81323/adani-green-energy-group-bags-world-s-biggest-solar-bid) of [elements](https://www.mindstick.com/forum/1440/wpf-button-with-multiple-text-elements) with the same [name](https://yourviews.mindstick.com/view/87450/how-to-generate-a-brand-name-using-linkedin-comprehensive-guide)?

## Replies

### Reply by Aryan Kumar

To get a selected [value](https://www.mindstick.com/articles/23219/an-optimized-description-adds-value-to-experience-and-in-turn-effectively-guest-posting-packages) from a group of elements with the same name, you can use the `querySelector()` method. The `querySelector()` method takes a selector as its argument and returns the first element that matches the selector.

The following code shows how to get a selected value from a group of elements with the same name:

```plaintext
var elements = document.querySelectorAll("input[name='my_input']");
var selectedValue = elements[0].value;
```

In this code, the `elements` variable is a collection of all the elements that have the `name` attribute set to `my_input`. The `selectedValue` variable is the value of the first element in the `elements` collection.

If there is no selected element, the `querySelector()` method will return `null`.

Here is another way to get the selected value from a group of elements with the same name:

```plaintext
var selectedValue = document.querySelector("input[name='my_input']").value;
```

In this code, the `selectedValue` variable is the value of the element that has the `name` attribute set to `my_input`.


---

Original Source: https://www.mindstick.com/forum/159728/how-to-get-a-selected-value-from-the-group-of-elements-with-the-same-name

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
