By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,729 Members | 1,363 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,729 IT Pros & Developers. It's quick & easy.

php array in javascript function

P: n/a
i've got an array created in php that I want to send over to a javascript function.

onclick = "return sjekk(<?echo $names; ?> )"

in my "sjekk" function, when I try to print an alert :

function sjekk(navn)
{
alert(navn); // or alert(navn[0])
return(false);
}

I get "function Array { [native code]}"

How do I print out the names I want?

obscurr
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
jn
"Obscurr" <ob*****@hotmail.com> wrote in message
news:44**************************@posting.google.c om...
i've got an array created in php that I want to send over to a javascript function.
onclick = "return sjekk(<?echo $names; ?> )"

in my "sjekk" function, when I try to print an alert :

function sjekk(navn)
{
alert(navn); // or alert(navn[0])
return(false);
}

I get "function Array { [native code]}"

How do I print out the names I want?

obscurr


Give your function a string created from your array instead:
<?
$name_string = implode( ',', $names);
?>
onclick = "return sjekk(<?echo $name_string; ?> )"
Jul 17 '05 #2

P: n/a
Obscurr wrote:
i've got an array created in php that I want to send over to a javascript
function.

onclick = "return sjekk(<?echo $names; ?> )"
try:

onclick = "return sjekk('<? echo $names; ?>')"

that is with a space between the <? and echo
and
with '' around your string.
In general: Look into your HTML produced by your PHP to find out why
Javascript has trouble with it.
Keep in mind your browser hasn't got a clue what process produced the HTML
in the first place.
Perl/PHP/C/ASP/Servlets etc.etc. it doesn't matter, only the output send to
the browser matters.
So always check that first.

Regards,
Erwin Moller

in my "sjekk" function, when I try to print an alert :

function sjekk(navn)
{
alert(navn); // or alert(navn[0])
return(false);
}

I get "function Array { [native code]}"

How do I print out the names I want?

obscurr


Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.