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

171
Vistas
How to disable another SELECT form?

I do have this script, which should hide/display DIVs based on selected option. It works great.

But I need to disable another DIVs (SELECTS, etc.) which are not currently choose based on the main select TYPE. The reason is I do have the same name for SELECT in every hidden DIV (possibility1); so when I choose in the first main select TYPE = 1 (and click to SEND button), it transfers values from TYPE = 2 (option value X, instead of eg. option value A).

Could you please help me? Thanks!

<form action="#" method="post" id="text">
  <select name="type" id="type">
    <option value="1">1</option>
    <option value="2">2</option>
  </select>
      
  
  <script>
     $(function() {$('#type').change(function(){ $('.possibility').hide(); $('#' + $(this).val()).show(); }); });                                        
      </script>
  
   <!-- IF TYPE = 1 -->                                
  <div id="1" class="possibility" style="<?php if($_POST[type]=="1" || $_POST[type]==""){echo 'display:block;';} else {echo 'display:none;';} ?>">
        <select name="possibility1" id="possibility1">
          <option value="A">A</option>
          <option value="B">B</option>
        </select>    
  </div>
  
  <!-- IF TYPE = 2 -->
  <div id="2" class="possibility" style="<?php if($_POST[type]=="2"){echo 'display:block;';} else {echo 'display:none;';} ?>">
        <select name="possibility1" id="possibility1">
          <option value="X">X</option>
          <option value="Y">Y</option>
        </select>                                          
  </div> 
  
  <input type="submit" name="send" value="send" class="button">
</form>

<?php
    if(isset($_POST['send'])) {  
    echo  $_POST[possibility1]; 
}
?>

I tried to add to script this code, but it doesn't work.

 $(function() {
  $('#type').change(function(){ 
    $('.possibility *').prop('disabled', true); 
    $('#' + $(this).val()+' *').prop('disabled', false); 
  });
});
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

$(function() {
  $('#type').change(function() {
    $('.possibility *').prop('disabled', true);
    $('#' + $(this).val() + ' *').prop('disabled', true);
  });
});

change into

document.queryselctor("#type").remove()

and you can share full code

about 4 years ago · Juan Pablo Isaza Denunciar

0

All right, this works :)

$(function() {
    $('#type').change(function() {
        $('.possibility').hide();
        $('.possibility select').attr("disabled", "disabled");         

        $('#' + $(this).val()).show();
        $('#' + $(this).val() + ' select').removeAttr("disabled");
    });
       
    $('#type').change();
});
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