Amit Kumar
Amit Kumar

Reputation: 11

javascript onclick working randomly

I am developing a virtual keyboard using PHP and JavaScript. Following is the simplest version.

  <html>
  <head>
  <link type="text/css" rel="stylesheet" href="styles.css"/>
  <script type="text/JavaScript" >
  function insert( s ) 
  {
        document.getElementById('comment').innerHTML+= s;
  }
  </script>
  </head>
  <body>

  <table>
        <tr>
              <td class="cell" ><p onclick="insert(this.innerHTML)" >a</p></td>
              <td class="cell"><p onclick="insert(this.innerHTML)">b</p></td>
        </tr>
        <tr>
              <td class="cell" ><p onclick="insert(this.innerHTML)">c</p></td>
              <td class="cell"><p onclick="insert(this.innerHTML)">d </p></td>
        </tr>
  </table>
  <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" >
        <textarea name="comment" id="comment"> </textarea>
        <input type='submit' value='Enter' name='beta' />
  </form>
  <?php
  if(isset($_POST['beta']))
  {
        echo $_POST['comment'] ;
  }
  ?>

  </body>
  </html>

It works fine untill I type in the <taxtarea> from the laptop, after which it does not take input from the virtual keyboard.

Upvotes: 1

Views: 301

Answers (1)

Ivan Nikolchov
Ivan Nikolchov

Reputation: 1574

You should use the value attribute of the textarea. Not innerHTML :

document.getElementById('comment').value += s;

Upvotes: 2

Related Questions