0

I am trying to render a page as below from my controller

$this->renderPartial("_ReservationDetails",array('rowarray'=>$rowarray,'CalendarID'=>$CalendarID),false,true);

in my view file, _ReservationDetails I have the following content

....
...
<td>
     <button id="btnPrint" onclick="return PrintReciept();" class="btn btn-small" type="button">Print Reservation</button>
</td>
....

I wrote a script inside the _ReservationDetails as below

<script>
   public function PrintReciept()
   {
      alert("I am here!");
      return false;
   }
</script>

But when I click on PrintReservation button it throws an error in the console. PrintReciept() is not defined

Why is it happening?

Vsevolod Goloviznin
  • 12,074
  • 1
  • 49
  • 50
Sachy
  • 45
  • 2
  • 10

1 Answers1

0

In onClick attribute you state onclick="PrintReciept();"

Your function you'd better register thru registerScript() method:

Yii::app()->clientScript->registerScript('script', "
  function PrintReciept()
  {
     alert('I am here!');
     return false;
  }
", CClientScript::POS_END);
Igor Savinkin
  • 5,669
  • 8
  • 37
  • 69
  • @Sachy, yes, in the view file. But might be also in the main layout file. – Igor Savinkin Dec 24 '14 at 13:10
  • I am actually taking a break , I had been coding something else untill now, will start off again in an hour.. and will 100% let you know. I believe it should work!! Thank you! – Sachy Dec 24 '14 at 15:54
  • This one worked for me >>> $(document).ready(function(){ $('#btnPrint').click(function(){ }); }); – Sachy Dec 24 '14 at 16:02