Jump to content

Passing array to textarea so that it's formatted (line breaks)


VFDinc

Recommended Posts

Ok, You guys have been great help, and I am learning a lot. I am making a social RPG game, and now I am trying to show the opponents information in a textbox after the player selects an opponent from a drop down list. I have no problem passing the array to the textarea, but I would like to format the data that is presented in the textarea. For example right now I just show Name, class, and level. I want to show in the textarea like this:

Name: Fitch

Class: Thief

Level: 15

 

instead of:

Name: Fitch Class: Thief Level: 15

Also I would like to retain Name, Class, and Level as variables, once the player finds an opponent he wants to fight. I will use Name, Class, and Level again.

 

<script type='text/javascript'>
      function select_opponent() {
         var opponent_stats = document.getElementById('opponent').value;
         document.getElementById('opponent_description').value = opponent_stats;
      }
  </script>

mysql_connect();

mysql_select_db('sok');

$result = mysql_query('select * from sokopps');

$options="";

while ($row=mysql_fetch_array($result)) {

    $Class=$row["Class"];
    $Name=$row["Name"];
$Level=$row["Level"];
$OppStats = "Name:".$Name ." Class: ". $Class ." Level: ". $Level;
    $options.="<OPTION VALUE=\"$OppStats\">".$Name;
}
?>
<strong>Select Opponent:</strong> 
<select id='opponent' name='opponent' onChange='select_opponent();'>
<OPTION VALUE=0>Choose your opponent
<?=$options?>
</SELECT>

    
  </div>
    <div id="apOppInfo">
        <div id="apOppStats"><textarea id='opponent_description' name='opponent_description'>
      </textarea></div>
        <div id="apOppImage"></div>
    </div>
    <div id="apStratList">
    <?php

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.