Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function is showing up with errors on the page (newbie)

Status
Not open for further replies.

je150

IS-IT--Management
Jun 10, 2003
33
0
0
US
I wrote a function to make sure that all fields are set before the information is submitted. Unfortunately the submit button does nothing and ie says there are errors on the page.

Code:
<script language=javascript>
function checkform()
	{
	if (document.createuser.Name.value=="")
		{
		alert ("Name Field is Blank");
		}
	else
	{
	if (document.createuser.Email.value=="")
		{
		alert ("Email Field is Blank");
		}
	}
	else
	{
	if (document.createuser.Password.value=="")
		{
		alert ("Password is Required to Create a User");
		}
	}
	else
	{
	document.createuser.action="create_check.php";
	document.createuser.method="post";
	document.createuser.submit();
	}
	}
</script>

and the form

Code:
<form name="createuser">
		<TD>Full Name:</TD>
		<td><input type="text" name="Name" size="24" maxlength="24"></TD>
	</tr>
	<tr>	
		<td>Email:</td>
		<td><input type="text" name="Email" size="24" maxlength="24">@email.com</td>
	</tr>
	<tr>
		<td>Password:</td>
		<td><input type="password" name="Password" size="8" maxlength="8"></td>
	</tr>
	<tr>
		<td></tr><td><input type="checkbox" name="admin_check">Admin Rights?</td>
	</tr>
	<tr>
		<td colspan="2" align="center"><input type="button" class="submit" value="Create" onclick="javascript:checkform();">
	</tr>
</form>

Im thinking i just did something stupid. Any help would be appreciated, im completely new to writing javascript..
 
Nevermind I fixed it!
After coding php for weeks, i figured out that you cant immediately close else statements in javascript

Code:
<script language=javascript>
function checkform()
{
    if (document.createuser.Name.value=="")
        {
        alert ("Name Field is Blank");
        }
    else
    {
    if (document.createuser.Email.value=="")
        {
        alert ("Email Field is Blank");
        }
    else
    {
    if (document.createuser.Password.value=="")
        {
        alert ("Password is Required to Create a User");
        }
    else
    {
    document.createuser.action="create_check.php";
    document.createuser.method="post";
    document.createuser.submit();
    [COLOR=red]}}}[/color]
}
</script>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top