Firefox can't parse php in this way, any body have good way to resolve this problem?

Discussion in 'PHP' started by suhe, Sep 10, 2010.

  1. #1
    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!
     
    suhe, Sep 10, 2010 IP
  2. Cozmic

    Cozmic Member

    Messages:
    146
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    48
    #2
    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.
     
    Cozmic, Sep 10, 2010 IP
  3. HuggyEssex

    HuggyEssex Member

    Messages:
    297
    Likes Received:
    4
    Best Answers:
    2
    Trophy Points:
    45
    #3
    Try this,

    <span onclick="call_js_sctipt('<?php echo $parameter; ?>')"> Button </span>
    PHP:
     
    HuggyEssex, Sep 11, 2010 IP
  4. suhe

    suhe Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    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!
     
    suhe, Sep 11, 2010 IP
  5. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #5
    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:
     
    Last edited: Sep 11, 2010
    MyVodaFone, Sep 11, 2010 IP
  6. lowridertj

    lowridertj Well-Known Member

    Messages:
    2,882
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    195
    #6
    what is your actual parameter being echoed or shown in the tag?
     
    lowridertj, Sep 11, 2010 IP
  7. suhe

    suhe Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    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?
     
    suhe, Sep 12, 2010 IP
  8. HungryMinds

    HungryMinds Active Member

    Messages:
    216
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    63
    #8
    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>
     
    Last edited: Sep 12, 2010
    HungryMinds, Sep 12, 2010 IP
  9. suhe

    suhe Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    I have used location.href resolved my problem.
    Thank you for your help!
     
    suhe, Sep 13, 2010 IP