1

I have three input radio buttons like

<input type="radio" name="specific_parent" id="parent_one" class="radio" value="existing_parent"><label class="redio_label" for="existing_parent">Existing Parent</label>
<input type="radio" name="specific_parent" id="parent_two" class="radio" value="prospective_parent"><label class="redio_label" for="prospective_parent">Prospective Parent</label>
<input type="radio" name="specific_parent" id="parent_third" class="radio" value="other"><label class="redio_label" for="other">Other</label>

I have applied jQuery validation like this:

rules: {
   specific_parent: {
      required: true
   }
},
messages: {
  specific_parent: {
      required: 'Please select radio button'
  }
}

problem is that it display the error message after first input radio button and my layout is break.

enter image description here

9
  • where do you want to display it? Commented Apr 23, 2015 at 7:29
  • And exactly what validation plugin are you using? Commented Apr 23, 2015 at 7:30
  • under all three radio buttons!! Commented Apr 23, 2015 at 7:30
  • Where is the code that displays the message? Commented Apr 23, 2015 at 7:31
  • jQuery Validation Plugin v1.13.1 * jqueryvalidation.org Commented Apr 23, 2015 at 7:32

2 Answers 2

1

Use errorPlacement

 errorPlacement: function (error, element) {
      error.insertBefore(element);
}
Sign up to request clarification or add additional context in comments.

2 Comments

Is there any function like insertBefore() to put the errors after element??
Yes there are functions error.insertBefore(element) and error.insertAfter(element);
0
<div class="input-container">
<input type="radio" name="specific_parent" id="parent_one" class="radio" value="existing_parent"><label class="redio_label" for="existing_parent">Existing Parent</label>
<input type="radio" name="specific_parent" id="parent_two" class="radio" value="prospective_parent"><label class="redio_label" for="prospective_parent">Prospective Parent</label>
<input type="radio" name="specific_parent" id="parent_third" class="radio" value="other"><label class="redio_label" for="other">Other</label>
</div>
<style type="text/css">
 .input-container{position:relative;} 
</style>

you have to add css of your parent div of inputs then change the position of error message using positon absolute in css and using top,left or bottom properties you can adjust where you want to display.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.