 i have already completed a couple of tutorials on forms and jquery ajax forms with jquery and flexible and semantic forms with a little jquery but i wanted to show another example of using a simple jquery script to enhance functionality this example will be about the comment form on a wordpress powered site depending upon your configuration wordpress will validate the comment form for required fields in my configuration i want to make sure that users fill in their name and email address if you submit my comment form without those wordpress will perform server side validation but do you really want users to see this error page wouldnt it be so much better if we used to javascript to validate on the client side so that they never have to leave the form i think so before we get started i created a sample of the wordpress comment form see example page creating the markup i have tweaked my markup somewhat from the default wordpress comment form so you will need to make changes to account for your markup here is the markup for my form form action= method= post id= commentform p class= required denotes required field p ol class= forms li label for= author name span class= required span label input type= text class= requiredfield name= author id= author size= 22 li li label for= email e mail span class= required span label input type= text class= requiredfield name= email id= email size= 22 li li label for= url website label input type= text name= url id= url size= 22 li li class= textarea label for= comment comments span class= required span label textarea class= requiredfield name= comment id= comment cols= 100% rows= 10 textarea li li class= subscribe to comments input type= checkbox name= subscribe id= subscribe value= subscribe label for= subscribe notify me of followup comments via e mail label li li class= buttons button type= submit name= submit id= submit add comment raquo button li ol form i dont think there is much that i need to discuss about that markup it is pretty standard the only thing to mention is the class name of requiredfield on the form fields that i want to be required note i also removed the action on the form so that the sample form cannot really be submitted to the database the jquery i of course am going to show this example using jquery but you could create something comparable with any other javascript library or just with some plain old javascript once the document is loaded lets start by adding a function for when the comment form is submitted $ document ready function $ form commentform submit function hellip next we want to remove any errors if they are showing and create a flag that will let us know if an error has occured $ document ready function $ form commentform submit function strong$ form commentform error remove var haserror = false strong hellip ok here is where we really start to do some coding i want to take each form field that has a class of requiredfield check to see if it is empty copy the name of the label and remove the required asterisk traverse to the parent list item and append the error message here is where we will also set the haserror flag so that we know an error has occurred $ document ready function $ form commentform submit function $ form commentform error remove var haserror = false strong$ requiredfield each function if jquery trim $ this val == var labeltext = $ this prev label text replace $ this parent append span class= error labeltext is a required field span haserror = true strong hellip finally you want to check the haserror variable to determine whether or not you should submit the form to the server $ document ready function $ form commentform submit function $ form commentform error remove var haserror = false $ requiredfield each function if jquery trim $ this val == var labeltext = $ this prev label text replace $ this parent append span class= error labeltext is a required field span haserror = true strongif haserror return false strong note the end of the script is slightly different on the example form because i did not want to actually submit the form conclusion just another simple example of how we can improve the user experience by using jquery like usual there are jquery plugins out there that can do the same thing but i think it is important to understand how to do things yourself plus that is only 17 lines of javascript compared to much much more for a plugin anyone have any ideas on how to improve the script 