[SOLVED] HOW to pass "new line" to JS ?

hi, I have this variable to pass to "confirm" menu link.


$msg_delete = 'Esta seguro de que desea borrar la '. $model->descripcion .' ?. \r\n Si la cuota esta Liquidada se cambia de estado. \r\n Si esta Preliquidada se elimina del sistema.';



but i see "\r\n" on the screen…

and this on the firebug:




if(confirm('Esta seguro de que desea borrar la Cuota: 2012/3 ?. \\r\\n Si la cuota esta Liquidada se cambia de estado. \\r\\n Si esta Preliquidada se elimina del sistema.')

So "\" is scaped … to "\\"…

how can I avoid that !!

Best Regards.

Hey,

how do you output the variable $msg_delete? Please show us your code.

For JavaScript line breaks, use [font="Courier New"]\n[/font] and not [font="Courier New"]\r\n[/font].

here is …


$msg_delete = 'Esta seguro de que desea borrar la '. $model->descripcion .' ?. \r\n Si la cuota esta Liquidada se cambia de estado. \r\n Si esta Preliquidada se elimina del sistema.';


$this->menu=array(

	array('label'=>Yii::t('app', 'Manage') . ' ' . $model->label(2), 'url'=>array('admin','uselastfilter'=>true)),


	array('label'=>Yii::t('app', 'Delete') . ' ' . $model->label(), 

			'url'=>'#',

			'visible' => $model->estado == 'P' or ($model->estado == 'L' and $model->importe_pagado == 0),			

			'linkOptions' => 

				array('submit' => array('delete', 'id' => $model->id), 

					'confirm'=>$msg_delete,)

					),

	

);



I read on interntet that for Browser compatibility is better to use "\r\n" …

Well I spoke out of my experience, which, I admit, doesn’t include cross-browser compatibility.

Now, you may want to read this: http://stackoverflow.com/questions/1841452/new-line-in-javascript-alert-box

You should use double quotes rather than single:

Wrong:


$msg_delete = 'Esta seguro de que desea borrar la '. $model->descripcion .' ?. \r\n Si la cuota esta Liquidada se cambia de estado. \r\n Si esta Preliquidada se elimina del sistema.';

Right:


$msg_delete = "Esta seguro de que desea borrar la ". $model->descripcion ." ?. \r\n Si la cuota esta Liquidada se cambia de estado. \r\n Si esta Preliquidada se elimina del sistema.";

Reference:

http://php.net/manual/en/language.types.string.php

But this for a JavaScript output, not PHP?

PERFECT !!!

Not really, looking at the example, the string is created in PHP in this case.

You’re right though, in javascript single quotes could be used.