If you take a look at the generated HTML, it'll look something like this :
<input type='button' value='send mails' onclick="sendmails(Type your Question here testin to post from chrome)">
There are some quotes missing arround the string you're passing as parameter to the JS function sendmails
So, I'd say add some quotes arround it ; a bit like this :
echo "<input type='button' value='send mails' onclick=\"sendmails('".$sendQuestion."')\">";
EDIT : added more stuff...
But, if $sendQuestion
contains quotes, it'll get you another error... So it might be usefull to
- bad idea : either replace those
'
with \'
with something like str_replace
- or "transform" the string to a valid-JS one, with, for instance,
json_encode
The second solution will get you a PHP code like this one (note that json_encode
adds double-quotes arround the string... so it becomes harder to embed directly in the function call... so let's use a variable) :
$sendQuestion = "Type your Question' here testin to post from chrome";
$json = json_encode($sendQuestion);
echo '<script type="text/javascript">' . "\n";
echo 'var myString = ' . $json . ';' . "\n";
echo '</script>' . "\n";
echo "<input type='button' value='send mails' onclick=\"sendmails(myString)\">";
And the generated HTML will be :
<script type="text/javascript">
var myString = "Type your Question' here testin to post from chrome";
</script>
<input type='button' value='send mails' onclick="sendmails(myString)">
Which is much more nice :-)
Maybe not perfect yet... But, by now, I think you get the point ;-)
As a sidenote : json_encode
only exists since PHP 5.2... so you might want to check the version of PHP you are using...