Jump to content

validating a form


manick

Recommended Posts

Hi all,I have the following in the head: function chkName(billFamilyName){ if (billFamilyName.value=="") { alert("Please write your name") billFamilyName.focus() }}and this in the body: <td><input type="text" onblur="chkName(this)" name="billFamilyName" maxlength="30"></td>but it is returning an object expected on the onblur, can someone give me an idea as to what I have done wrong, I am assuming it's something to do with whats in the () but am not sure. Any help appreciated.Tanick

Link to comment
Share on other sites

*editi'm getting strange errors with this code :)Just put a button on the page that checks all the fields when the user submits the form, otherwise these alerts can get annoying

Link to comment
Share on other sites

The code you pasted earlier worked ok for me, i never received any errors.The only thing that bugged me was if i left the textbox blank and tried to move of the page i kept getting the alert, which was annoying :)

Link to comment
Share on other sites

This is the code i am using that works ok, try it and let me know what happens.

<html><head><script type="text/javascript">function chkName(billFamilyName){if (billFamilyName.value=="") {alert("Please write your name")billFamilyName.focus()}}</script></head><body><form><input type="text" onblur="chkName(this)" name="billFamilyName" maxlength="30"></form></body></html> 

Link to comment
Share on other sites

Hi Scott,I managed to get my original code working by taking out a link to an external script. The problem I can't get my head around is using a mix of external scripts and functions in the header, If I have a link to an external script in the script tag in the head, the functions in the head when called return an "object expected" error. Thanks mateyNick

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...