grs5211 Posted June 2, 2009 Share Posted June 2, 2009 I want to send a variable concatenated with some text to a javascript function. Clearly this will work. echo "<SCRIPT LANGUAGE='javascript'>errorMessages('This is not a valid ID);</SCRIPT>"; However I want to do this: echo "<SCRIPT LANGUAGE='javascript'>errorMessages($_REQUEST["UserID"] + ' is not a valid ID);</SCRIPT>"; Any ideas? Quote Link to comment Share on other sites More sharing options...
anupamsaha Posted June 2, 2009 Share Posted June 2, 2009 I want to send a variable concatenated with some text to a javascript function. Clearly this will work. echo "<SCRIPT LANGUAGE='javascript'>errorMessages('This is not a valid ID);</SCRIPT>"; However I want to do this: echo "<SCRIPT LANGUAGE='javascript'>errorMessages($_REQUEST["UserID"] + ' is not a valid ID);</SCRIPT>"; Any ideas? Sure. Do this: echo "<SCRIPT LANGUAGE='javascript'>errorMessages(<?php echo $_REQUEST["UserID"]?> + ' is not a valid ID);</SCRIPT>"; Quote Link to comment Share on other sites More sharing options...
anupamsaha Posted June 2, 2009 Share Posted June 2, 2009 Sorry, I made one mistake. Please change as: echo "<SCRIPT LANGUAGE='javascript'>errorMessages({$_REQUEST['UserID']} + ' is not a valid ID');</SCRIPT>"; Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted June 2, 2009 Share Posted June 2, 2009 Hmm... this is a hard one. :-\ Looks like you sort of solved it, but had a brain freeze. echo "<SCRIPT LANGUAGE='javascript'>errorMessages('{$_REQUEST["UserID"]} is not a valid ID');</SCRIPT>"; Just put in the quotes correctly with some PHP variable interpolation syntax. Quote Link to comment Share on other sites More sharing options...
grs5211 Posted June 2, 2009 Author Share Posted June 2, 2009 Thanks . anupamsaha, I tried your code first and it did not compile. ken2k7, yours worked. Thanks to you both for responding. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.