Hi there,
This may or may not be a dumb question, but I've never come across it before.
Can you point to a javascript 'onsubmit="return validation()"' on a form, but WITHIN PHP tags?

Such as the below.

function validation(){
	
var reply = document.getElementById('comreply');
var div = document.getElementById('errormsg');

if((reply.value == '') || (reply.value == ' ')){
	div.innerHTML = "Please type a reply";
	reply.focus();
	return false;}
else{
	return true;}
}
<? echo "<form name=\"reply\" method=\"post\" action=\"replydone.php\" onsubmit=\"return validation()\"><textarea name=\"comreply\" id=\"comreply\" cols=\"25\" rows=\"4\"></textarea></form> ?>

Thanks for all replies.

Hi,

In your example, you're essentially just outputting a string of HTML, with inline JavaScript to the browser, so yes, you can do that.

That seemed quite simple (only if you know, of course), but does that answer your question, or have I misunderstood?

R.

Thanks for the reply blocblue...

you see thats what I thought at first and that it shouldnt have made any difference at all as it was all correct, just in PHP tags, however when putting it all in and testing it with nothing in the text area box, no errormsg was displayed and the form submitted anyway, instead of returning false.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.