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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need help form validation

Status
Not open for further replies.

DataSpy

Technical User
Nov 15, 2002
39
US
hello i'm having trouble with some form validation, the code is
<script language=&quot;JavaScript&quot;>
<!--
function validate(form)
{
if (form.sub_name.value.length == 0)
{
alert(&quot;Please enter your first name.&quot;)
form.sub_name.focus()
return false
}
}
//-->
</script>
in the head of the html document and then
<tr height=&quot;5%&quot;>
<td width=&quot;35%&quot;>
<strong>Name:</strong>
</td>
<td width=&quot;65%&quot; align=&quot;right&quot;>
<input type=&quot;text&quot; id=&quot;sub_name&quot; name=&quot;sub_name&quot;>
</td>
</tr>
in the body, and nothing happens when I hit submit.
Any help would be greatly appretiated!

 
i have all of that i just didn't want to put all of the code in here
 
all of the code is
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>
<html>
<head>
<title>DVD Admin Page</title>
<script language=&quot;JavaScript&quot;>
<!--
function validate(form)
{
if (form.sub_name.value.length == 0)
{
alert(&quot;Please enter your first name.&quot;)
form.sub_name.focus()
return false
}
}
//-->
</script>
</head>
<body>
<center><h3>DVD Admin Page</h3></center><br>
<form action=&quot;url&quot; method=&quot;post&quot; name=&quot;form&quot;>
<!-- start divider -->
<table border=&quot;0&quot; bordercolor=&quot;#000000&quot; width=&quot;100%&quot; height=&quot;80%&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;>
<tr>
<td align=&quot;center&quot;>
<!-- start title -->
<table border=&quot;0&quot; bordercolor=&quot;#000000&quot; width=&quot;25%&quot; height=&quot;2%&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;>
<tr>
<td align=&quot;center&quot;>
<strong>Submit DVD</strong>
</td>
</tr>
</table>
<!-- end title -->
<!-- start outer black border -->
<table border=&quot;1&quot; bordercolor=&quot;#000000&quot; width=&quot;25%&quot; height=&quot;15%&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;>
<tr>
<td>
<!--start form 1 -->
<table border=&quot;1&quot; width=&quot;100%&quot; height=&quot;100%&quot; cellpadding=&quot;1&quot; cellspacing=&quot;0&quot;>
<tr height=&quot;5%&quot;>
<td width=&quot;100%&quot; align=&quot;center&quot; colspan=&quot;2&quot;>
<strong>Main Information</strong>
</td>
</tr>
<tr height=&quot;5%&quot;>
<td width=&quot;35%&quot;>
<strong>Name:</strong>
</td>
<td width=&quot;65%&quot; align=&quot;right&quot;>
<input type=&quot;text&quot; id=&quot;sub_name&quot; name=&quot;sub_name&quot;>
</td>
</tr>
<tr height=&quot;5%&quot;>
<td width=&quot;35%&quot;>
<strong>Catagory:</strong>
</td>
<td width=&quot;65%&quot; align=&quot;right&quot;>
<input type=&quot;text&quot; name=&quot;sub_catagory&quot;>
</td>
</tr>
<tr height=&quot;5%&quot;>
<td width=&quot;35%&quot;>
<strong>Year:</strong>
</td>
<td width=&quot;65%&quot; align=&quot;right&quot;>
<input type=&quot;text&quot; name=&quot;sub_year&quot;>
</td>
</tr>
<tr height=&quot;5%&quot;>
<td width=&quot;35%&quot;>
<strong>ISBN:</strong>
</td>
<td width=&quot;65%&quot; align=&quot;right&quot;>
<input type=&quot;text&quot; name=&quot;sub_isbn&quot;>
</td>
</tr>
<tr height=&quot;5%&quot;>
<td width=&quot;100%&quot; align=&quot;center&quot; colspan=&quot;2&quot;>
<strong>Extra Information</strong>
</td>
</tr>
<tr height=&quot;5%&quot;>
<td width=&quot;35%&quot;>
<strong>Studio:</strong>
</td>
<td width=&quot;65%&quot; align=&quot;right&quot;>
<input type=&quot;text&quot; name=&quot;sub_studio&quot;>
</td>
</tr>
<tr height=&quot;5%&quot;>
<td width=&quot;35%&quot;>
<strong>Director:</strong>
</td>
<td width=&quot;65%&quot; align=&quot;right&quot;>
<input type=&quot;text&quot; name=&quot;sub_director&quot;>
</td>
</tr>
<tr height=&quot;5%&quot;>
<td width=&quot;35%&quot;>
<strong>Actors:</strong>
</td>
<td width=&quot;65%&quot; align=&quot;right&quot;>
<input type=&quot;text&quot; name=&quot;sub_actor&quot;>
</td>
</tr>
</table>
<table border=&quot;0&quot; width=&quot;100%&quot; height=&quot;100%&quot; cellpadding=&quot;1&quot; cellspacing=&quot;0&quot;>
<tr>
<td align=&quot;center&quot;>
<input type=&quot;submit&quot; value=&quot;Submit&quot;>
</td>
</tr>
</table>
<!-- end form -->
</td>
</tr>
</table>
<!-- end outer black border -->
</td>
<td align=&quot;center&quot;>
<!-- start title -->
<table border=&quot;0&quot; bordercolor=&quot;#000000&quot; width=&quot;25%&quot; height=&quot;2%&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;>
<tr>
<td align=&quot;center&quot;>
<strong>Delete DVD</strong>
</td>
</tr>
</table>
<!-- end title -->
<!-- start outer black border -->
<table border=&quot;1&quot; bordercolor=&quot;#000000&quot; width=&quot;25%&quot; height=&quot;15%&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;>
<tr>
<td>
<!--start form 2 -->
<table border=&quot;1&quot; width=&quot;100%&quot; height=&quot;100%&quot; cellpadding=&quot;1&quot; cellspacing=&quot;0&quot;>
<tr height=&quot;5%&quot;>
<td width=&quot;100%&quot; align=&quot;center&quot; colspan=&quot;2&quot;>
<strong>Main Information</strong>
</td>
</tr>
<tr height=&quot;5%&quot;>
<td width=&quot;35%&quot;>
<strong>Name:</strong>
</td>
<td width=&quot;65%&quot; align=&quot;right&quot;>
<input type=&quot;text&quot; name=&quot;del_name&quot;>
</td>
</tr>
<tr height=&quot;5%&quot;>
<td width=&quot;35%&quot;>
<strong>ISBN:</strong>
</td>
<td width=&quot;65%&quot; align=&quot;right&quot;>
<input type=&quot;text&quot; name=&quot;del_isbn&quot;>
</td>
</tr>
</table>
<table border=&quot;0&quot; width=&quot;100%&quot; height=&quot;100%&quot; cellpadding=&quot;1&quot; cellspacing=&quot;0&quot;>
<tr>
<td align=&quot;center&quot;>
<input type=&quot;submit&quot; value=&quot;Submit&quot;>
</td>
</tr>
</table>
<!-- end form -->
</td>
</tr>
</table>
<!-- end outer black border -->
</td>
</tr>
</table>
<center><font color=&quot;red&quot;>You must enter all Main Information in order to submit DVD into database</font></center>
<!-- end divider -->
</form>
</body>
</html>

 
>> i have all of that i just didn't want to put all of the code in here

Given that your problem directly related to the submit button, you'd have thought that it would have been the most relevant section of code to post. Anyway...

I ran the code above, and couldn't even see the submit buttons on the screen (I kid you not). I had to remove the two bits of code saying
Code:
height=&quot;15%&quot;
before I could see them (suggest you do a search for those).

The
Code:
validate
function is never being called - for either of the submit buttons, or the form onSubmit event, so it's no wonder the validation routine doesn't work.

If you modify your
Code:
<form>
tag to read:

Code:
<form action=&quot;url&quot; method=&quot;post&quot; name=&quot;myForm&quot; onSubmit=&quot;return(validate(this));&quot;>

Then it will call your validation code.

Incidentally, I'd suggest you get hold of a good Javascript tutorial book... They normally provide an invaluable resource for beginners, and it's generally good fun to work through the exercises in them.

Hope this helps,

Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top