0

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.

Edited by ben.marks: n/a

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by ben.marks
0

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.

0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.