passing parameters in ajax through php echo command
hi,
i have passed following parameters in ajax function,
onclick = "agU(<?php echo $u . ' , ' . $msg; ?>);"
its not working. when i test the same function in following way it runs fine. onclick = "agU(<?php echo $u; ?>);"
am i commiting any mistake in supplying variable???
please help..
servis
Junior Poster in Training
82 posts since May 2008
Reputation Points: 10
Solved Threads: 0
hi,
i have passed following parameters in ajax function,
onclick = "agU(<?php echo $u . ' , ' . $msg; ?>);"
its not working. when i test the same function in following way it runs fine. onclick = "agU(<?php echo $u; ?>);"
am i commiting any mistake in supplying variable???
please help..
You need to 'quote' your vars: onclick = "agU('<?=$u;?>','<?=$msg;?>');"
I've used 'short tags' above - which is frowned upon [PLEEZE no more self-righteous 'I disagrees'!! IDGAD], but you can swap these for the full <?php echo $u;?> and <?php echo $msg;?> if you want.
You could also build a complete parameter string in pHp first (including quote marks) and then just include the php string - without encompassing quote marks.
From what I can see, your problem was quote marks - or should I say, the lack of them.
diafol
Rhod Gilbert Fan (ardav)
7,796 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080