I am using ajax to pass php variable to javasccript function as shown below for my particular application.

i am using the foolowing function from ajax.js freely available from net to implement the ajax functionality as

var abc = new sack();

PHP portion which passes the response text:
************************************
<?
$table=$_GET;

gg($table);
gg($table)
{
echo "<a href='#' onclick='showfield($table) '>show</a>";
}

?>


javascript:
*********
showfield(ss)
{

alert(ss);
}


Problem:
*******

1] When $table is having a string with only numeric characters for eg: "123" we get the alert

2] When $table is having a string with alphanumeric characters for eg: "123efg" we get the error report as "missing ) after argument list"

3] When $table is having a string with alphanumeric characters for eg: "efg123" or "abcdfr" we get the error report as "efg123 is not defined" or "abcdfr is not defined".

Take a look at the generated source code, try to analyze it and you would know the answer to all your questions.

You need to pass strings with double or single quotes so you should use the escape character
try
echo "<a href='#' onclick='showfield(\"".$table."\") '>show</a>";

The Answer is really great!!!!!!!

Really a Great solution

this solution helped me in my code thanks ;) well i was coding something else.. i was forgetting to give a quote -.- thank you so much ^^

thanks a lot..it helped me...god bless u

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.