Jump to content

Recommended Posts

Posted

Caros amigos.

Estou com um pequeno problema em solucionar um erro de ATIVAR/DESATIVAR campos com checkbox.

Com ajuda dos amigos, consegui em parte efetuar um processo que estava pesquisando muito.

O problema que ocorre agora é o seguinte:

- quando clico no CHECKBOX ele ativa o input-[text] e um button-[submit] <== até aqui tudo bem

o erro:

- se selecionar o checkbox novamente sem clicar no button-[submit] o checkbox desabilita todos os input e button do formulário.

Como faço para quando clicar no checkbox para habilitar o input e button o checkbox fica desativado e volta a ficar ativado, após clicar no button-[altera/salvar].

O código está assim:

 <fieldset>

              <div class="box-header with-border" style="background: #E0F2EC;">

                <div class="col-sm-8 invoice-col"> 
                  <h3 class="box-title" style="font-size:18px;">
                    <?php echo '<strong>'.$produtoClie.' - '.$descrProd.'</strong>'; ?>
                  </h3> 
                </div>

                <form name="form_hab" action="" enctype="multipart/form-data" method="POST" >
                   <div class="col-sm-4 invoice-col">      
                    <small class="pull-right">         
                      <input type="text" id="item<?=$produtoClie?>" name="qtdeCota" maxlength="10"
                             class="txtCota bloqueia"
                             onkeypress="return numberOnly(event)"
                             value="<?php echo $cotaQtde; ?>" disabled 
                             style="width:50%; height:28px; text-align:right; font-size:15px;" >                    

                      <input type="hidden" name="cotaItensId" value="<?php echo $cotaItensId; ?>">
                      <input type="hidden" name="cotaNumero" value="<?php echo $cotaNumero;?>" />

                      <button type="submit" name="ajusQtde" id="ajusQtde" class="btn btn-success btn-xs" 
                              title="Salvar a Quantidade do Item" value="Ajustar" disabled 
                              style="width:20%; height:28px; margin-top:-5px; font-size:14px;" >
                              Ajustar
                      </button>  
                      &nbsp;&nbsp;&nbsp;
                      <input name="agreecheck" type="checkbox" onClick="agreesubmit(this,'item<?=$produtoClie?>');">
                      <label title="Clica no CHECKBOX para Acionar o Ajuste"
                              style="text-align:right; font-size:16px; color:#000065;">Alterar</label>
                    </small>
                   </div>                    
                </form>

              </div>  

           <fieldset>
             
             
           <!-- o código do javascript, está assim -->
            <script language="JavaScript" >    
              
                var checkobj
                function agreesubmit(el){
                  checkobj=el
                  if (document.all||document.getElementById){
                    for (i=0; i<checkobj.form.length; i++){ 
                      var tempobj=checkobj.form.elements[i]
                      if(tempobj.type.toLowerCase()=="text"||tempobj.type.toLowerCase()=="submit")
                      tempobj.disabled=!checkobj.checked
                    }
                  }
                }  

            </script>    

 

Grato,

Toarelli

Posted

boas,

 

Existem várias maneiras de conseguir o que pretendes.

Uma delas seria adicionar o atributo "onsubmit" na form, e voltar a "checkar" o checkbox.

Algo tipo:

<form onsubmit="a_tua_check_box.checked = true" ... >

 

cumps

Cumps,

cc

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.