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

92
Views
Hide a field based on populated value from database php

I would like to hide input field based on dropdown value. So two values are auto populated from database stone1 and stone 2 so if stone1 is pupated I want karat to be hidden and if stone 2 then carat and if any more values populated both should be hidden

<label for="form" class="control-label">=Service</label>
<select  id="form1" class="custom-select custom-select-sm select2" >
   <option selected="" disabled>Select services First</option>
   <?php
      ?>
   <!-- <option value="<?php echo $row['id'] ?>" ><?php echo $name ?></option> -->
   <?php endwhile; ?>
   <div class="col-md-2">
      <div class="form-group ctd" data-cid="ctd">
         <label for="ctd">stone1</label>
<select class="form-control" id="ctd" name="ctd">
<option>24</option>
<option>22</option>
<option>20</option>
<option>18</option>
<option>16</option>
<option>14</option>
</select>
</div>  
</div> 
<div class="col-md-2">
   <div class="form-group ctg" data-cid="ctg">
      <label for="ctg">stone2</label>
      <select class="form-control" id="ctg" name="ctg">
         <option>24</option>
         <option>22</option>
         <option>20</option>
         <option>18</option>
         <option>16</option>
         <option>14</option>
      </select>
   </div>
</div>

So two values are auto-populated from database stone1 and stone 2 so if stone1 is populated I want karat to be hidden and if stone 2 then carat and if any more values populated both should be hidden

I tried this code but it hides only one and does not work at all

<script>    
  var form1 = jQuery('#form1');
  var select = this.value;
  form_id.change(function () {
    if ($(this).val() == 'stone1') {
      $('.ctd').show();             
    } else {
      $('.ctg').hide(); 
    }               
  });       
           
</script>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

     (function ($) {
 
     $(function () {
        var form1 = jQuery('#form1');
   var select = this.value;
         $('#form1').change(function(){
             if( $(this).val()==="1" ){
                 $("#ctd").show()
                $("#ctg").hide()
                $('label[for="ctg"]').hide();
                $('label[for="ctd"]').show();
             } else {
                $("#ctg").show()
                 $("#ctd").hide()
                $('label[for="ctd"]').hide();
                $('label[for="ctg"]').show();
             }
         });
 
 
         $('#form1').trigger("change");
     });
 
 }(jQuery));
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!