Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
XML
<HTML>
<HEAD>
<TITLE>Simple Form</TITLE>
<Script type="javascript">
function demo()
{
var x=document.form[0].Fullname.value;
if(x==null || x=="")
{
alert("fill name ");
return=false;
}
}
</Script>
</HEAD>
<BODY >
<Form name="form1" onSubmit="return demo();">
Name:<input type="text" name="Fullname">
<input type="submit" value="submit">
</Form>
</BODY>
</HTML>
Posted
Comments
Sandeep Mewara 11-May-12 6:04am    
And what will you do?

HTML
<HTML>
<HEAD>
<TITLE>Simple Form</TITLE>
<Script type="javascript">
function demo()
{
var x=document.form[0].Fullname.value;
if(x==null || x=="")
{
alert("fill name ");
return false;//Error was here
}
}
</Script>
</HEAD>
<BODY >
<Form name="form1" onSubmit="return demo();">
Name:<input type="text" name="Fullname">
<input type="submit" value="submit">
</Form>
</BODY>
</HTML>


Error was not on line 17 but in the function called from line 17.
 
Share this answer
 
HTML
<html>
    <HEAD>
	<TITLE>Simple Form</TITLE>
	<Script language ="javascript"> // error was here : either u specifiy language="javascript" or type="text/javascript"
	    function demo()
	    {
		var x= document.form.Fullname.value; // if u have multiple forms with the same name then only u can use array else u should not use array
		if(x==null || x=="")
		{
		    alert("fill name ");
		    return false;//Error was here
		}
	    }
	</Script>
    </HEAD>
    <BODY >
	<Form name="form" onSubmit="return demo();"> // error was here form name and variable was diffrent
	    Name:<input type="text" name="Fullname">
	    <input type="submit" value="submit">
	</Form>
    </BODY>
</HTML>
</html>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900