简体   繁体   中英

append text from object to textarea not working

Here is the code:

<?php
$_SESSION['currentlocation'] = "combat.php";

if($_SESSION['ambush'] && $_SESSION['flee']) {

    for($i = 0; $i < sizeOf($_SESSION['enemies']); $i++) {
        $scaling = 20 - $_SESSION['enemies'][$i] -> luck;
        if($_SESSION['enemies'][$i]-> rank >= 20 && $_SESSION['enemies'][$i]-> rank <     
 40) {

            $prob = rand(1, 100);

            if($prob <= 100) {              
 //                if($prob <= 75 - $scaling * 3.8) {
                if($_SESSION['comboAttack'] < 2) {
                    $_SESSION['comboAttack'] = 2;
                }

                $_SESSION['enemies'][$i]->comboAttack = 2;
                $_SESSION['enemies'][$i]->attackMessage="Enemy #".strval($i)."pulls off   
         a 2-hit combo. \n";

            }

        }
        else if($_SESSION['enemies'][$i]-> rank >= 40 && $_SESSION['enemies'][i]-> rank 
        < 60) {
            $prob = rand(1, 100);

            if($prob <= 50 - $scaling * 3.8) {
                if($_SESSION['comboAttack'] < 3) {
                    $_SESSION['comboAttack'] = 3;
                }

                $_SESSION['enemies'][$i]->comboAttack = 3;
                $_SESSION['enemies'][$i]->attackMessage="Enemy #".strval($i)."pulls off 
         a 3-hit combo. \n";

            }
            else if($prob <= 75 - $scaling * 3.8) {
                if($_SESSION['comboAttack'] < 2) {
                    $_SESSION['comboAttack'] = 2;
                }

                $_SESSION['enemies'][$i]->comboAttack = 2;

            }
        }

        if($_SESSION['enemies'][$i] != null) {
           // $_SESSION['enemies'][$i]->attack($i);

           // echo $_SESSION['enemies'][$i]->attackMessage;                
        }    
 ?>                  
<script type="text/javascript">
    $(document).ready(function() {

        $('#combatinfo').append('<?php if($_SESSION['enemies'][$i] != null) echo 
   $_SESSION['enemies'][$i]->attackMessage; ?>');                        
    });
</script>    
<?php      
    }
?>
<button type="button">Defend</button> <button type="button">Flee</button>
<form action="index.php" method="post">
<input type="submit" name="submit" value="Submit" />
</form>
<?php           
}

As the title states I'm trying to append the text in the text-field of an object(skinhead) to a textarea. The above code does not work. However when I replace some code with this:

 <script type="text/javascript">
    $(document).ready(function() {

        $('#combatinfo').append('<?php if($_SESSION['enemies'][$i] != null) echo 
   "HELLO WORLD!" ?>');                        
    });
</script> 

This works.

The text in the object is not null, so how come it is not displaying? Thank you for your time.

Replace

  $_SESSION['enemies'][$i]->attackMessage="Enemy #".strval($i)."pulls off   
     a 2-hit combo. \n";

with

$_SESSION['enemies'][$i]->attackMessage="Enemy #".strval($i)."pulls off a 2-hit combo.&#13;&#10;";

and so on...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM