junxiong
(Junxiong)
August 10, 2010, 10:23am
1
Hi I need to call a javascript in one of textField so I wrote like this :
<?php echo $form->textField($model,'barang_id',array('onchange'=>'refreshNama("#MasukBarang_barang_id", "#barangkode")')); ?>
But the Yii will encode the string causes the javascript is invalid. I’ve tried add ‘encode’=>‘false’ but I don’t feel this the right one, I thought it somekind like add prefix “js:” in front of the string. I’ve tried that too, but the string still encoded.
Does anybody know how to fix this?
mdomba
(Maurizio Domba Cerin)
August 10, 2010, 10:45am
2
I tryed it now and it’s working but you have to pay attention to the use of single/double quote…
use it like this
<?php
echo $form->textField($model,'barang_id',array(
'encode'=>false,
'onchange'=>"refreshNama('#MasukBarang_barang_id', '#barangkode')"
));
?>
that way you get this
<input onchange="refreshNama('#MasukBarang_barang_id', '#barangkode')" ...
NOTE: if you use the double quotes in the function call you get this code that is not OK
input onchange="refreshNama("#MasukBarang_barang_id", "#barangkode")" ...
junxiong
(Junxiong)
August 10, 2010, 11:34am
3
mdomba:
I tryed it now and it’s working but you have to pay attention to the use of single/double quote…
use it like this
<?php
echo $form->textField($model,'barang_id',array(
'encode'=>false,
'onchange'=>"refreshNama('#MasukBarang_barang_id', '#barangkode')"
));
?>
that way you get this
<input onchange="refreshNama('#MasukBarang_barang_id', '#barangkode')" ...
NOTE: if you use the double quotes in the function call you get this code that is not OK
input onchange="refreshNama("#MasukBarang_barang_id", "#barangkode")" ...
yeah, that ones can do.
I just wonder isn’t there something like prefix “js:” to prevent encode? But I am not quite sure where can use this prefix.
So for now I am using your way, mdomba …
thank you
mdomba
(Maurizio Domba Cerin)
August 10, 2010, 11:37am
4
My was as you say is per documentation… hehe…
check what the documentation says under the attribute $htmlOptions for tag() method - http://www.yiiframew …Html#tag-detail
mashegol
(Mashegol)
June 22, 2016, 11:56am
5
I see the
'encode' => false
option does not exist in Yii2. How do I achieve the same result?