idy Posted September 13, 2006 Share Posted September 13, 2006 Hello !I have the following JS function[code]function test(id) {var result = '<? echo $array[' + id + ']; ?>';alert(result);}[/code]which does not send anything. How is it possible to send the javascript variable id to the PHP variable (array) $array ?Thanks a lot. Quote Link to comment Share on other sites More sharing options...
Gruzin Posted September 13, 2006 Share Posted September 13, 2006 [code]$array[' + id + '];[/code] What's this meant to be? Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted September 13, 2006 Share Posted September 13, 2006 you are mixing js and php there buddy!PHP will stop running once the page has been served to the client - php can do no more after that until the next request is sent.you wil have to populate and array explicitly in js usign the php array you have constructed and then use id to traverse it. Quote Link to comment Share on other sites More sharing options...
idy Posted September 13, 2006 Author Share Posted September 13, 2006 OK thanks a lot. Quote Link to comment Share on other sites More sharing options...
Gruzin Posted September 13, 2006 Share Posted September 13, 2006 You could use this to get the point:[code]<?php$id = "5"; echo "<a href='#' onClick=\"alert ('$id');\">Get it</a>";?>[/code] Quote Link to comment Share on other sites More sharing options...
idy Posted September 13, 2006 Author Share Posted September 13, 2006 Actually the variable $array is already used in my PHP script before writing the JS function.If I write :[code]var result = '<? echo $array[0]; ?>';[/code]I do have the content of $array[0] into result.The only thing I am trying to do is to retrieve the JS variable id instead of the hard-coded value 0 into $array. Or is still the same problem ? Thanks ! Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted September 13, 2006 Share Posted September 13, 2006 For that you need to look at AJAX.Ken 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.