Try appending $to_id to the form ids, so that they are unique (e.g. <form id="message_area_<?php echo $to_id; ?>" ...).

And then update showMessageArea function to do this:

var message_area = document.getElementById('message_area_'+this.id);

This way you will be operating on the desired form element.

As a refactoring suggestion, I would suggest using a single form instead and make id parameter to be <input type='hidden' name='id' id='message_id' value=''> and set it's value from the showMessageArea(...) like this: