submitButton


(Martde) #1

How do I hide/activate a button on a form?

<div id="clickme1" class="row buttons" >

	&lt;?php echo CHtml::submitButton('Save',array('submit' =&gt; '/tirociniStage/index.php?r=docente/create'),array(&quot;id&quot;=&gt;&quot;studente&quot;)); ?&gt;


&lt;/div&gt;	

I try with this,but don’t work

<script>

$().ready(function(){

&#036;('studente').click(function(){


    &#036;('clickme1').toggleClass('hidden');


});

});

</script>

Can you help me????


(Maurizio Domba Cerin) #2

$(‘clickme1’) should be $(’#clickme1’)

$(‘studente’) should be $(’#studente’)


(Martde) #3

Don’t work same…:-(((

Can you help me???

Should I remove the <script>???


(Maurizio Domba Cerin) #4

Try this code:




<?php 

    Yii::app()->getClientScript()->registerScript("myinit1","

           $('#studente').click(function(){

                  $('#clickme1').toggleClass('hidden');

           });

    ");

?>



Edit

<?php echo CHtml::submitButton(‘Save’,array(‘submit’ => ‘/tirociniStage/index.php?r=docente/create’),array(“id”=>“studente”)); ?>

should be




<?php echo CHtml::submitButton('Save',array(

             'submit' => '/tirociniStage/index.php?r=docente/create',

              "id"=>"studente"

)); ?>




(Martde) #5

No don’t work…:frowning:


(Maurizio Domba Cerin) #6

The code is working, but I think the problem is in the logic…

First… do you have in your CSS the class hidden?




.hidden {display:none;}



Second… the submit button when clicked will open a new page so what happens is that you click the button, the button is hidden but then the ‘/tirociniStage/index.php?r=docente/create’ is called and displayed as a new page, so you don’t see any more the page with the hidden button…

maybe to use ajaxSubmitButton ?




  <div id="clickme1" class="row buttons" >

    <?php echo CHtml::ajaxSubmitButton('Save','','',array(

              "id"=>"studente"

    )); ?>

  </div>



but check the parameters… the second one is the URL you need, if it’s empty it means current page

This way when you click the button the button is hidden and the page remains with the hidden button

Hope it helps…


(Martde) #7

yes i have a class

.hide {display:none;} in my css

No, I need to make a 2 buttons one visible when I call a form and the other botton invisible when I call another form … as I do?


(Maurizio Domba Cerin) #8

If you have in the javascript code “toggleClass(‘hidden’)”, then the class should be .hidden not .hide