Can't Interpolate variable into a string

C

Chris M.

I have a JavaScript function that sends a GET request to a cgi script
and displays the results from the script. The call to the function
looks like this:

ajaxpack.getAjaxRequest("/cgi-bin/myscript.cgi",
"searchstring=cooking&pageone=Submit", processGetPost, "txt")

This works, and I get the correct results back. But I want to replace
the searchstring "cooking" with the value of a variable called
"search". I have tried several different ways to interpolate this
variable, but have not found the correct syntax.

Can anyone help me out?

Thanks!

Chris M.
 
S

SAM

Le 12/18/08 12:01 AM, Chris M. a écrit :
I have a JavaScript function that sends a GET request to a cgi script
and displays the results from the script. The call to the function
looks like this:

ajaxpack.getAjaxRequest("/cgi-bin/myscript.cgi",
"searchstring=cooking&pageone=Submit", processGetPost, "txt")

This works, and I get the correct results back. But I want to replace
the searchstring "cooking" with the value of a variable called
"search". I have tried several different ways to interpolate this
variable, but have not found the correct syntax.

on back or on sent ?

"searchstring="+search+"&pageone=Submit", processGetPost, "txt")

?
 
T

Thomas 'PointedEars' Lahn

Chris said:
ajaxpack.getAjaxRequest("/cgi-bin/myscript.cgi",
"searchstring=cooking&pageone=Submit", processGetPost, "txt")

This works, and I get the correct results back. But I want to replace
the searchstring "cooking" with the value of a variable called
"search". I have tried several different ways to interpolate this
variable, but have not found the correct syntax.

RTFM:
Can anyone help me out?

My Magic 8-Ball says: Outlook not so good.


PointedEars
 
J

JR

If 'search' is a global variable defined in another part of the
script, maybe:

ajaxpack.getAjaxRequest("/cgi-bin/myscript.cgi",
"searchstring=" +search +"&pageone=Submit", processGetPost, "txt")

Joao Rodrigues
 
T

Thomas 'PointedEars' Lahn

JR said:
If 'search' is a global variable defined in another part of the
script, maybe:

ajaxpack.getAjaxRequest("/cgi-bin/myscript.cgi",
"searchstring=" +search +"&pageone=Submit", processGetPost, "txt")

`search' does not have to be declared a global variable for this to
work. It only needs to be the name of a property of an object in the
scope chain; that includes global variables but does not exclude the
other possibilities.


PointedEars
 
C

Chris M.

Thanks for the replies, folks,

I solved the problem by using the eval() method. I constructed the
required function call to
my ajaxpack.getAjaxRequest function as a long string, then put it into
eval(), which created
executable JavaScript code .

(Sorry for the newbie-ish question. I'm a Perl programmer who is
slowly getting the hang of JavaScript!)

- Chris M.
 
T

Thomas 'PointedEars' Lahn

Chris said:
Thanks for the replies, folks,

I solved the problem by using the eval() method. I constructed the
required function call to my ajaxpack.getAjaxRequest function as a
long string, then put it into eval(), which created executable
JavaScript code .

Sounds like the worst possible solution. A good solution has already
been posted; I suggest you use it.

<http://jibbering.com/faq/#eval>


PointedEard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top