John
John

Reputation: 4638

jquery form validation - error message position

This could well be a duplicate of an existing question. Can anyone recommend a Javascript or Jquery form validation script which offers the following.

  1. Error text can be positioned anywhere on the page rather than just alongside or underneath the field.
  2. Error message text should be in the page itself rather than buried in a separate js file - as the page will be available in several languages.
  3. The script needs to check for required fields and for valid email addresses. (I imagine this is pretty standard)

Normally I'd just use the validation controls which come with asp.net, but in this case I'm not using .net

Cheers

Edit - html here. And yes, we're trying to add a new skin to an old site!

<form method="post">
<table>
<tr>
    <td class="td-right" valign="top">Name:</td>
    <td><input style="width:400px"  type="text" name="name" /></td>
</tr>
<tr>
    <td class="td-right" valign="top">Telefon:</td>
    <td><input style="width:400px"  type="text" name="telephone" /></td>
</tr>
<tr>
    <td class="td-right" valign="top">Email-Adresse:</td>
    <td><input style="width:400px"  type="text" name="from" /></td>
</tr>
<tr>
    <td class="td-right" valign="top">Thema:</td>
    <td><input style="width:400px"  type="text" name="subject" /></td>
</tr>
<tr>
    <td class="td-right" valign="top">Nachricht:</td>
    <td><textarea style="width:400px; height:200px"  name="message"></textarea></td>
</tr>
<tr>
    <td>&nbsp;</td>
    <td><input class="button" type="submit" name="submit" value="senden" /></td>
</tr>
</table>
</form>

Upvotes: 0

Views: 1430

Answers (1)

Deepu Sasidharan
Deepu Sasidharan

Reputation: 5309

Look the example....

 $("#f_valid").validate(
  {
      rules:
      {
          firstname:"required",
          address:"required",
          pin:
          {
              required:true,
              digits:true,
              minlength:6,
          },
           gender:"required",
           dob:
           {
              required:true,
              dateISO:true,
           },
           statename:"required",

           mobile:
           {
               required:true,
               digits:true,
               rangelength: [10, 12]
           },
          email:
          {
               required:true,
               email:true,
          },
          password:
          {
             required:true,
             minlength:6,
          },
          confirmpassword:
          {
            required:true,
            equalTo:'#pass'
          },
           keyskills:"required",
           course_done:"required",
           university:"required",
           yearof passing:
           {
             required:true,
             digits:true,
           },
            mark1:
            {
              required:true,
              digits:true,
            },

            photo:
            {
                required:true,
                extension:'jpg|png|gif',
            },
            resume:
            {
               required:true,
               extension:'txt|doc|docx|pdf',
            },
      },
      errorPlacement:function(error, element)
    {
        if($(element).attr("name")=="gender")
        {
            $(element).parent().append(error);
        }else
        {
        $(error).insertAfter(element);
        }   
    },

  });

Upvotes: 1

Related Questions