disable/enable buton de submit

Aici postaţi orice este legat de tehnologiile "client side". HTML, HTML5, XHTML, CSS, CSS3, XML, Standarde
Manual JS: http://www.phpromania.net/jsmanual/index.html

Moderatori: eyecon, Moderatori

chuck_n
Average Member
Mesaje: 70
Membru din: Vin Iun 03, 2011 9:57 am

disable/enable buton de submit

Mesajde chuck_n » Vin Feb 17, 2012 10:52 am

Am banala situatie

Cod: Selectaţi tot


<form action="register.php" method="post">
          <textarea name="terms" rows="15" cols="105" class='scroll'>
                  General Terms.... bla bla
          </textarea><br /><br />
           <input type="checkbox" id="readTerms" name="agree" > I have read and agreed to the  Terms and Conditions.<br />

<input  id="submitBusiness" type="submit"  value="Submit" disabled="disabled">
</form>
   


De fiecare data cand dau pe checkbox butonul sa treaca din starea enable in disable sau invers.


Am incercat

Cod: Selectaţi tot

$('#readTerms').change( function() {
  $('#submitBusiness').attr('disabled', !this.checked);
});


sau

Cod: Selectaţi tot

$('#readTerms').click(function() {
    var buttonsChecked = this.checked;
    if (buttonsChecked == true){
        $('#submitBusiness').removeAttr('disabled');
    }else{
        $('#submitBusiness').attr('disabled', 'disabled');
    }
});


dar fara rezultatul dorit



X-spert
PHPRomania Supporter
Mesaje: 19
Membru din: Joi Iul 28, 2011 2:56 pm

Salut

Mesajde X-spert » Vin Feb 17, 2012 11:37 am

Incearca asa:

Cod: Selectaţi tot

<html>
   <head>
      <title>Test</title>      
       <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
      <script>
         $(document).ready(function(){
            var checked = true;
            $('input#readTerms').click( function(){
               if (checked) {
                  $(this).attr('checked',true);
                  $('input#submitBusiness').removeAttr('disabled');
                  checked = false;
               } else {
                  $(this).attr('checked',false);
                  $('input#submitBusiness').attr('disabled','disabled');
                  checked = true;
               }                  
            });
         });
      </script>
   </head>
   <body>
      <form action="register.php" method="post">
         <textarea name="terms" rows="15" cols="105" class='scroll'>
            General Terms.... bla bla
         </textarea><br /><br />
         
         <input type="checkbox" id="readTerms" name="agree" > I have read and agreed to the  Terms and Conditions.<br />

         <input  id="submitBusiness" type="submit"  value="Submit" disabled="disabled">
      </form>
   </body>
</html>

Bafta!

Avatar utilizator
kleampa
Senior Member
Mesaje: 2774
Membru din: Dum Iul 10, 2005 2:12 pm
Localitate: Bucuresti
Contact:

Mesajde kleampa » Vin Feb 17, 2012 2:05 pm

exista si $(this).is(":checked")


Înapoi la “HTML/JavaScript/CSS”

Cine este conectat

Utilizatori ce ce navighează pe acest forum: Bing [Bot] și 6 vizitatori