Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

203
Vistas
how to get input group radio value from input text box

I need to store the input fields with selected ones, how can I be able to do that with help of jQuery, Javascript, any idea?

<div class="input-group">
  <div class="input-group-prepend">
    <div class="input-group-text">
    <input type="radio" name="choosen">
    </div>
  </div>
 <input type="text"  name="opt[]"  />
  <br />
</div>

<div class="input-group">
  <div class="input-group-prepend">
    <div class="input-group-text">
    <input type="radio" name="choosen">
    </div>
  </div>
   <input type="text"  name="opt[]"  />
  <br />
</div>
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

It depends on a few things:

Where do you want to store?

If you intend to store it in the browser, then you can use localStorage or sessionStorage to do so. If you want to store it on the server, then you will need to send it somehow, maybe as form data, or an AJAX request, or via WebSocket.

When do you want to invoke the store?

If you want to invoke the store upon each value change, then you could add a change event, like:

let options = document.querySelectorAll("input[name=choosen]");
for (let option of options) {
    option.addEventListener('change', function() {
        storeCheckedOption(options);
    });
}

So far, so good. Now let's implement storeCheckedOption:

function storeCheckedOption(options) {
    for (let option of options) {
        if (option.checked) {
            store("choosen", option.value);
            return;
        }
    }
    store("choosen", "");
}

Now let's implement store. For now I assume that you intend to store it into localStorage, but you can change the way things are stored in the way you intend:

function store(key, value) {
    localStorage.[(value ? "set" : "remove") + "Item"](key, value);
}

Naturally, you can do this with AJAX as well if you intend to store it on server-side.

However, if you want to store the chosen radio button on the server when the form is being submitted, then you do not need to do anything on the client-side. Instead, you can parse the request parameters on server-side and store the chosen item there.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Here is the code :)

var store;

$('button').on('click', function(){
    let value = $('input[type=radio]:checked').parents('.input-group').find('input[type=text]').val();
  store = value;
  
  console.log(store);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="input-group">
  <div class="input-group-prepend">
    <div class="input-group-text">
    <input type="radio" name="choosen">
    </div>
  </div>
 <input type="text"  name="opt[]"  />
  <br />
</div>

<div class="input-group">
  <div class="input-group-prepend">
    <div class="input-group-text">
    <input type="radio" name="choosen">
    </div>
  </div>
   <input type="text"  name="opt[]"  />
  <br />
</div>
<br>
<button>Store</button>

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can get the input field value, by clicking on the radio button. Make sure you add something on the input field, before click on the radio button. Checkout the Fiddle

$('input[type=radio]').on('click', function() {

  var inputValue = $('input[type=radio]:checked').closest('.input-group').find('input[type=text]').val(); /* You can use let instead of var */

  console.log(inputValue);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="input-group">
  <div class="input-group-prepend">
    <div class="input-group-text">
      <input type="radio" name="choosen">
    </div>
  </div>
  <input type="text" name="opt[]" />
  <br />
</div>

<div class="input-group">
  <div class="input-group-prepend">
    <div class="input-group-text">
      <input type="radio" name="choosen">
    </div>
  </div>
  <input type="text" name="opt[]" />
  <br />
</div>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda