Hi Guys
I have a button in a separate view called btnSubmitMisc.
Attached to this button is a function that changes it’s class to make it appear ‘disabled’ after it was clicked:
<?php
echo CHtml::link($caption,'#', array(
'id'=>'btnSubmitMisc',
'submit'=>array($actionUrl),
'class'=>'myCHtmlButton',
));
?>
<?php
Yii::app()->clientScript->registerScript('submitTest', "
$('#btnSubmitMisc').click(function(){
if($('#btnSubmitMisc').hasClass('myCHtmlButton'))
{
$('#btnSubmitMisc').removeClass('myCHtmlButton');
$('#btnSubmitMisc').addClass('myCHtmlButtonClicked');
}
else
{
return false; // Don't submit if class is myCHtmlButtonClicked
}
});
");
?>
Now whenever I need a button in my main-view, I just use this:
<?php
$this->renderPartial('...btnSubmitMisc', array(
'actionUrl'=>'contact',
'caption'=>'Submit',
));
?>
The problem is that if I add more of these buttons to the main-view, the jquery does not work correctly because all buttons then have the same ID. I can pass each button a unique id from the main-view, but how do you get the jquery to dynamically use the ID of the correct button? How do you pass the ID to jquery? I don’t think that I can use classes, because I’m already using classes to make the button able/disable.