Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

201
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!