How do I feed string variable holding multiline value in it to jquery method like prepend? I need it to construct a form pass by drupal search module like - $('#divsearch').prepend('<?php print $search_box; ?>').
Thanks a bunch.
I think the problem is that you can have carriage returns or new lines in you string lets take out the php and show what i mean
$('#divsearch').prepend('<div />');
this would work
$('#divsearch').prepend('<div>some text that goes
in a div</div>');
this does not work
$('#divsearch').prepend('<div>some text that goes'+
'in a div</div>');
this woould
Use json_encode()
to encode the string, like this:
$('#divsearch').prepend('<?php print json_encode($search_box); ?>');
This will encode newlines as instead of literally rendering them...giving you your current syntax errors.