I think you might be having a problem if your PHP is outputting any line breaks. eg:
// BAD:
$('<div class="input select"><label for="Gender">
Gender</label>').appendTo(...)
// GOOD:
$('<div class="input select"><label for="Gender">Gender</label>').appendTo(...)
If this is the case, replace the linebreaks with a space or with nothing:
// change from this:
$('<?php echo $form->input("blah", ...); ?>').appendTo(...)
// to this:
$('<?php echo str_replace(array("\r\n", "\r", "\n"), "", $form->input("blah", ...)); ?>')
.appendTo(...)
... or if you want to keep the new lines, you'll need to escape them with a slash.
// this gives "Unterminated string literal"
var x = 'abc
def';
// this gives you "abcdef"
var x = 'abc\
def';