Page 1 of 1

spaces in text to alert box

Posted: Wed Aug 20, 2008 6:36 pm
by amount
hello. I'm using Ubuntu and Mozilla. I have a button in a php script which calls a javascript function displaying an alert box with text passed as a parameter.
echo "<input type='button' ondblclick=confirm(".$txt.");>";

I've tried all sorts of variations confirm'"(.txt."'), javascript confirm( etc.

If the $txt="Hello", it works fine. If $txt="Hello world" the alert box doesn't appear at all.
Thanks
Tony

Re: spaces in text to alert box

Posted: Wed Aug 20, 2008 8:37 pm
by lukewilkins
Try this:

Code: Select all

<?php
 
$txt = 'Hello World!';
echo '<input type="button" value="YourButton" ondblclick="confirm(\'' . $txt . '\');"';
 
?>
Do you really want ondblclick for a button? Why not onclick?

Hope that helps!

Re: spaces in text to alert box

Posted: Wed Aug 20, 2008 9:08 pm
by amount
No. This is a test for something else which exhibits the same problem.
Tony

Re: spaces in text to alert box

Posted: Wed Aug 20, 2008 9:13 pm
by lukewilkins
Uhhm, no, actually it works perfectly. The message board however is not displaying it correctly.

Just replace [BACKSLASH] with an actual backslash and test. ... It works ... you need single quotes around your phrase in your confirm dialogue but therefore you also need to escape them.

Code: Select all

<?php
 
$txt = 'Hello World!';
echo '<input type="button" value="YourButton" ondblclick="confirm([BACKSLASH]'' . $txt . '[BACKSLASH]');"';
 
?>

Re: spaces in text to alert box

Posted: Wed Aug 20, 2008 9:18 pm
by amount
Works now. Thanks very much
Tony

Re: spaces in text to alert box

Posted: Thu Aug 21, 2008 10:13 am
by lukewilkins
No problem, glad I could help!

Luke