PHP onsubmit in the form not going to the fuction.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
azadms
Forum Newbie
Posts: 5
Joined: Sat Oct 24, 2009 7:28 am

PHP onsubmit in the form not going to the fuction.

Post by azadms »

I have a form through ‘onsubmit’ calling a function validation(). But not going to the function at all. Why?

<form action="member.php" method="post" name="frmlogin" id="frmlogin" onsubmit="return validation();" enctype="multipart/form-data">
.
.
.
</form>

The function code :-
<script language="javascript">

function validation()
{

if(document.frmlogin.title.value=='')
{
alert("Please enter Title")
document.frmlogin.title.focus();
return false;
}
}
</script>
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: PHP onsubmit in the form not going to the fuction.

Post by Mark Baker »

This is a javascript question, nothing at all to do with PHP

Have you tried debugging using FireBug or similar to confirm that it isn't executing the validation() function?
godwinsam
Forum Newbie
Posts: 9
Joined: Wed Sep 16, 2009 11:01 pm

Re: PHP onsubmit in the form not going to the fuction.

Post by godwinsam »

Hello,

I have worked out the following way,

<form action="member.php" method="post" name="frmlogin" id="frmlogin" onsubmit="return validation();" enctype="multipart/form-data">
<input type="submit" name="name" value=""/>
<input type="text" name="title" value="value" size="40" maxlength="40"/>
</form>

The function code :-
<script language="javascript">

function validation()
{

if(document.frmlogin.title.value=='')
{
alert("Please enter Title")
document.frmlogin.title.focus();
return false;
}
}
</script>


Its working fine now.
Please try the above coding.

Thanks & Regards,
Post Reply