views:

32

answers:

1

I'm using the jQuery Validation plug-in is it possible to trow the errors in a specific div? like

<label>userName:</label>
<input type="text" name="user"/>
<span id="userErr">you must enter username</span>

is this possible? 10x

A: 

There are several ways to do this, as described by the documentation. You can use:

<label>userName:</label>
<input type="text" name="user"/>
<span class="userErr"></span>

errorPlacement: function(error, element) {
    // error references a label element, element refers to the invalid element
    element.next('.userErr').append(error);
},

or investigate errorElement, wrapper, and errorLabelContainer

Bobby Jack
10x but what if i have 2 filed?can i use the id of the input filed?
@user186585 - You can use use `<span class="err">` and do `.next('.err')` instead...but the validation plugin already does this exact error placement with a `label`, are you sure you don't want to just change that to a `<span>`? (that's what the `errorElement: 'span'` option would do).
Nick Craver