This is off the top of my head and hand-typed, so probably won't work as is (and definitely needs the usual browser-compatible approach to getElementByID). But the principle is what you want, I think.
Apologies for the color coding; GFY doesn't respect the code tag like it does the php tag. And a few words tweaked to avoid hahahaha-age.
PHP Code:
<div id="errormsg" </div>
<for_m name=myform action="whatever" method="get">
hahahahahahaha type=text name="checkme">
hahahahahahaha type=submit value="Submit" onclick="if (documen_t.forms.myform.checkme = = 'bad') {documen_t.getElementByID('errormsg').innerHTML='You entered an invalid value'; return false;">
</form>
Cheers
-b