I've been trying to get this to work for alittle over a week and im about to lose hope in my capabilities. I need some help, someone who can write the working code and explain what is happening.

Basically, i want to display a message that is called from posts.php and have is display right in between the checkbox of the form and the submit button in my loginform. I don't just want a solution that can only be used for submitting forms, i want to be able to display a message anywhere in a website at any given time without being dependent on buttons being clicked or forms being submitted.

As an example, I used a form that if both username and password would be left blank it would display an error. I wanted to use this just as an example so others could understand what I was trying to accomplish easily. Let me stress again that I don’t want a solution dependent on form submissions or the form calling a javascript function, I want to be able to display a message anywhere in a section of a website at anytime. Without further adieu, here are the files:

Just to mention i’ve seen a solution that involved calling a javascript function that would use innerhtml and an elementID and it seemed great but that particular solution to a question i saw was done in a way that was a massive head ache because the script had to be written after the form in order to actually edit the innerhtml of the <div> and the only way to call it in printMessage() would make the calling to that javascript at the very top of main.php before the function is even defined giving object errors and null errors.

Special thanks to hkx from you know where that is keeping me sane. Here is a simpler version of what i want to accomplish. Pretty much i tried over doing it by putting the JavaScript in functions.php and ineffectually ended up calling the function before its creation(or something). Here is the solution. You must always have the javascript code under the <div> you will be changing.

For future people, here are some tags for others find this page:
'document.getElementById(...)' is null or not an objec
<body onload=
onSubmit="return"
Dynamic Form Error
Display Error
PHP
Javascript
Html