Jump to content

[SOLVED] Send a variable to a function from an echo statement


grs5211

Recommended Posts

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?

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>";

 

Hmm... this is a hard one. :-\ Looks like you sort of solved it, but had a brain freeze. :P

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.