I have wirte a php code like this: <span onclick="call_js_sctipt('<?=$parameter?>')"> Button </span> Run this code in IE, IE can parse this code successfully, but in firefox can't parse it. I have found the root cause is Firefox can't parse javascript function's parameter with php parameter like this '<?=$parameter?>'. If i change <?=$parameter?> to a static parameter, firefox can parse it correctly. Any body have a good way to resolve this problem? Hopes to hear your good solution. Thank your very much!
Browsers have nothing to do with PHP. The HTML is the only factor. The browser doesn't see any PHP, as it's server-side.
Thanks for both of your reply. I have tried HuggyEssex's way before, it doesn't work. I thisk this problem is probably due to parameter parse between javascript and php. If php transmit parameter use this way -----onclick="call_js_sctipt('<?=$parameter?>')", there will be problem in firefox when browing this page. But i still haven't find a direct way to resolve this problem. Only i can see the resolve way now is to use another way to transimit this parameter like POST, but this will take me lots of effort to change my code. I will be very appreciated for any ideas!
Hmm.. this simple javascript alert function works on ff and ie, so maybe the problem is somewhere else. Anyway in theory you should just be able to post your call_js_sctipt in between the <script tags <?php $parameter = "this"; ?> <script type="text/javascript"><!-- function call_js_sctipt(i) { if (i == 'this') { alert ("Span Area Works!"); } } // --></script> <span onclick="call_js_sctipt('<?php echo $parameter; ?>');">Button</span> PHP:
Thank you for both of your help! I have resolve this problem. But i still haven't found the root cause. I have listed my detail code below. php code: foreach ($component as $info) { <td><span class="casebutton" title="Click to delete current component" onclick="delcomponent('<?=$info['id']?>');">Delete</span></td> } javascript code: var delcomponent = function(id) { var id = id; $.post("delcomponent.php?id="+ id); //alert(id); window.history.go(0); } In the beginning i can't transmit $info['id'] to javascript, but follow MyVodaFone's debug way, i tried to add alert information into javascript to debug my function. But i fonud if i add alert into my javascript, the parameter can transmit successfully under Firefox. It's very strange. Any way i have found out an way to resolve this problem. Does anybody have some idea about this?
Hi! Try This Method: <?php foreach ($component as $info){ ?> <td> <span class="casebutton" title="Click to delete current component" onclick="delcomponent('<?php echo $info; ?>');">Delete</span> </td> <?php } ?> <script> var delcomponent = function(id) { location.href="delcomponent.php?id="+id; } </script> PHP: Or U Can Use: <span onclick="location.href='delcomponent.php?id=<?php echo $info; ?>';">Delete</span>