简体   繁体   中英

how to store a drop down list value grouped with radio button to database

i have a laravel form with a list of radio buttons, where one button has to be grouped with the drop down.when the that particular radio button is checked, and the drop down list value can be chosen. When the form has been submitted, I want the chosen value in the drop down to be stored to the database. i dont have problem in saving the other radio buttons, which has been configured in the controller and route I would like to know how to pass the chosen option value from the drop down to the database. Thanks The display is has follows Blade view

<div class="col-4 col-sm-4 col-md-2 col-lg-1">
  <div class="form-check">
    <input class="form-check-input" type="radio" name="glass_type" id="glass_type_own" value="own">
    <label class="form-check-label" for="exampleRadios3">OWN</label>
  </div>
</div>
<div class="col-4 col-sm-4 col-md-2 col-lg-1">
  <div class="form-check">
    <input class="form-check-input" type="radio" name="glass_type" id="glass_type_on" value="on">
    <label class="form-check-label" for="exampleRadios3">ON</label>
  </div>
</div>
<div class="col-4 col-sm-4 col-md-2 col-lg-2">
  <div class="form-check">
    <label class="form-check-label" for="exampleRadios3">
      <input class="form-check-input" type="radio" name="glass_type" id="glass_type_oth" value="" >
    </label>

    <select id="glass_type_oth_opt" class="form-control"  value="" >
      <option value="">OTHER </option>
      <option value="Choose 01"> Choose 01 </option>
      <option value="choose 02"> Choose 02 </option>
      <option value="Choose 03"> Choose 03 </option>
    </select>
  </div>
</div>

Controller


class submitted extends Controller
{
    function update(Request $req)
    {
        $sbtd = new sbtd;
        $sbtd->glass_type = $req->glass_type;
        $sbtd->save();
    }
}

Blade view

try this

<div class="col-4 col-sm-4 col-md-2 col-lg-1">
    <div class="form-check">
        <input class="form-check-input" type="radio" name="glass_type" id="glass_type_own" value="own">
        <label class="form-check-label" for="exampleRadios3">OWN</label>
     </div>
 </div>
 <div class="col-4 col-sm-4 col-md-2 col-lg-1">
      <div class="form-check">
           <input class="form-check-input" type="radio" name="glass_type" id="glass_type_on" value="on">
            <label class="form-check-label" for="exampleRadios3">ON</label>
        </div>
  </div>
  <div class="col-4 col-sm-4 col-md-2 col-lg-2">
       <div class="form-check">
            <label class="form-check-label" for="exampleRadios3">
            <input class="form-check-input" type="radio" name="glass_type" id="glass_type_oth" value="" >
             </label>

              <select id="glass_type_oth_opt" class="form-control">
                    <option value="">OTHER </option>
                    <option value="Choose 01"> Choose 01 </option>
                    <option value="choose 02"> Choose 02 </option>
                    <option value="Choose 03"> Choose 03 </option>
               </select>
            </div>
         </div>

jQuery

<script type="application/javascript">
    $(document).ready(function(){
        $("#glass_type_oth_opt").on("change", function () {

            const InputValue =  this.value;
            const input = document.getElementById('glass_type_oth');
            input.value = InputValue;
            input.checked = true;

            console.log(InputValue);

        });
    });
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM