Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Possible Duplicate:
passing array from php to javascript

i need to pass 'PhP array' to 'javascript function' here is my code...

    $eqt_param=Array();
for($i=1; $i<3; $i++)
{
    <select name="'.$eqt_param[$i].'" onchange="send(this.name)">

}

i want to pass this to

 <script>
 function send(Eqt_Param)
 {

 }
 </script>

after passing the value to javascript function i need to have 3 variable holding the values of an array...please help me to fix this.....

share|improve this question
2  
Is this the exact PHP code you're using currently? – jprofitt Nov 27 '12 at 13:42
The author of the question does not understand the background behind his question, which is why its twice as hard to provide an answer. Also the main purpose remains unclear. To the author: Perhaps you could elaborate and provide some more background to your question. Generally, you cannot use HTML code right from with PHP without either leaving the PHP parser for that block or using a function that outputs your content - such as echo() – Cummander Checkov Nov 27 '12 at 13:47
why do you give negative point fo no reason.. check and read both question... in my question iam using external php ,, in the link provided by you they have used inter php within script, so its different questions altogeather.. – Friend Nov 27 '12 at 13:52
I'm not the downvoter - but how you apply the script is rather irrelevant to the logical nature behind this question. Could you clarify your problem, perhaps repost your question more thoroughly and provide clear information? (Also note that you are using a for loop to create multiple select boxes. This is probably not what you want to do. You want to create one <select> and wrap that around your multiple <option> tags, wherein you use the attribute "value" to set the actual value of each option) – Cummander Checkov Nov 27 '12 at 13:55

marked as duplicate by deceze, N.B., gpojd, Somnath Muluk, Linger Nov 27 '12 at 14:04

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer

As always, encode as JSON in order to create a valid JavaScript literal.

var val = <?php echo json_encode($somevar); ?>;
share|improve this answer
hmmm but as you can see in my code iam trying to pass send(this.name) ....so that $eqt_param[$i] should be sent to javascript send function...after sending how to check how to check wthr the array been passed to javascript function or not..?i used dump(Eqt_Param) but it is not alerting anything.... – Friend Nov 27 '12 at 13:49
In what environment are you testing? Can you post the relevant portion of the actual output that is supplied to the client (browser) ? – Cummander Checkov Nov 27 '12 at 13:51
well i have an ajax where i need to pass array values from script ... so before passing to ajax page iam passing php arrays to java script... – Friend Nov 27 '12 at 13:54

Not the answer you're looking for? Browse other questions tagged or ask your own question.