admin管理员组文章数量:1295909
Well, before I proceed to another phase of my coding, just to make sure im not going to bark at the wrong tree, may I ask if it is possible to call a javascript function in php without any button click action to trigger it. i also dont consider onload() or onready() because im going to call the javascript function inside a foreach loop in php.. well the concept goes somehow like this:
<script type="text/javascript">
function callMe(){
alert('im called!');
}
</script>
<body>
<?php
.....
foreach($somevar as $var){
// assuming it will loop 5 times
callMe(); // well this is the part where im going to call the javascript function
}
?>
</body>
Thank you in advance.
******EDITED PART*****
here's the actual codes i plan to use:
function AddCoordinate( lat, long )
{
var path = LinePath.getPath();
path.push( new google.maps.LatLng( lat, long ) );
}
<?php
foreach($arrayOfPlotPoints as $key => $value){
$longitude = round($value['longitude'],5);
$latitude = round($value['latitude'],5);
$snrLevel = $value['snr_level'];
echo '<script
type="text/javascript">AddCoordinate('.$latitude.','.$longitude.')</script>
?>
actually that's the right answer..it already worked.. so im gonna provide an answer as well
Well, before I proceed to another phase of my coding, just to make sure im not going to bark at the wrong tree, may I ask if it is possible to call a javascript function in php without any button click action to trigger it. i also dont consider onload() or onready() because im going to call the javascript function inside a foreach loop in php.. well the concept goes somehow like this:
<script type="text/javascript">
function callMe(){
alert('im called!');
}
</script>
<body>
<?php
.....
foreach($somevar as $var){
// assuming it will loop 5 times
callMe(); // well this is the part where im going to call the javascript function
}
?>
</body>
Thank you in advance.
******EDITED PART*****
here's the actual codes i plan to use:
function AddCoordinate( lat, long )
{
var path = LinePath.getPath();
path.push( new google.maps.LatLng( lat, long ) );
}
<?php
foreach($arrayOfPlotPoints as $key => $value){
$longitude = round($value['longitude'],5);
$latitude = round($value['latitude'],5);
$snrLevel = $value['snr_level'];
echo '<script
type="text/javascript">AddCoordinate('.$latitude.','.$longitude.')</script>
?>
actually that's the right answer..it already worked.. so im gonna provide an answer as well
Share Improve this question edited Jun 28, 2012 at 10:05 Charmie asked Jun 28, 2012 at 9:46 CharmieCharmie 2,6307 gold badges34 silver badges47 bronze badges 5- 1 What you did is correct Wrap that with <script type="text/javascript"> </script> – madhairsilence Commented Jun 28, 2012 at 9:48
- 1 Could you explain what are you trying to achieve? Right now this is not making much sense to do it like this. – slash197 Commented Jun 28, 2012 at 9:49
- something like an inline javascript? – Charmie Commented Jun 28, 2012 at 9:50
- im actually going to pass the variables to a javascript function and store it in a javascript array.. that is why right there and then when the values are being exploded in the foreach loop, im going to pass it to the javascript function... i dont want to do it the way like this: store to a variable and pass to javascript – Charmie Commented Jun 28, 2012 at 9:52
- 2 It seems like you are confusing server-side functionality (PHP) with client-side functionality (Javascript). Could you edit your question to explain what you want to achieve and then how you have attempted to achieve it? – Andrew Leach Commented Jun 28, 2012 at 9:53
2 Answers
Reset to default 8Just output this:
echo '<script type="text/javascript">callMe()</script>';
thanks to Donatas.. now this is what i have:
function AddCoordinate( lat, long )
{
var path = LinePath.getPath();
path.push( new google.maps.LatLng( lat, long ) );
}
<?php
foreach($arrayOfPlotPoints as $key => $value){
$longitude = round($value['longitude'],5);
$latitude = round($value['latitude'],5);
$snrLevel = $value['snr_level'];
echo '<script
type="text/javascript">AddCoordinate('.$latitude.','.$longitude.')</script>
?>
it works :)
本文标签: calling Javascript function without any button to trigger it in PHPStack Overflow
版权声明:本文标题:calling Javascript function without any button to trigger it in PHP - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741627273a2389157.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论