2

i am trying to validate fields in modalbox however its not working below is my validation code

$("#formapplication").validate({
rules: {
        tb_name:{ required: true },
        tb_url: {required: true},
        tb_tag: {required: true},
        tb_desc: {required: true},
        tb_catg: {required: true}
        },
messages:{
        tb_name:{ required: "Please Enter Full name" },
        tb_url: {required: "Please Enter URL"},
        tb_tag: {required: "Please Enter Tag."},
        tb_desc: {required: "Please Enter Description."},
        tb_catg: {required: "Please Select Category."}
        }
    });

jquery validation plugin support modalbox but its simple html i write on same page not calling using ajax any idea pelase help.

below is xhtml

<div id="submitapplication" style="display:none">
<form action="" id="formapplication" name="formapplication" method="post">
<div class="submitapplicationbox">
<label>Name<input type="text" name="tb_name" id="tb_name" /></label>
<label>Url<input type="text" name="tb_url" id="tb_url" /></label>
<label>Tags<input type="text" name="tb_tag" id="tb_tag" /></label>
<label>Category<select name="select" id="tb_catg">
  <option value=""></option>
  </select></label>
<label>Description
<textarea cols="" rows="" name="tb_desc" id="tb_desc" ></textarea></label>
</div>
<div class="twiteraccountinfobox">
<label>Name<input type="text" name="tb_twaccount" id="tb_twaccount" /></label>
<div style="margin-top:20px;"><input type="button" id="submitapp" value="Submit Application" /></div>
<div id="response" style="display:none;"></div>
</div>    

2
  • Not sure, but one thing's not exactly right here: enclose your field names in quotes; objects in JS should define their members in quotes: {"tb_name": ...}. That surely won't solve your problem but it's a good thing to keep in mind when you create objects in JS. Commented Mar 20, 2009 at 11:00
  • I can't see anything obviously wrong with your code - it matches that given by the valdiation documentation fine. Perhaps if you provided your markup too so I could throw together a test page I could help a bit more. Commented Mar 20, 2009 at 11:23

3 Answers 3

1

i was missting class required on all my inputs that i am using for validation

<input type="text" id="tb_name" class="required" />
Sign up to request clarification or add additional context in comments.

Comments

0

Ah, first off, add a # to your form action so it's form action="#". The # doesn't fix it, but I have run into IE issues before without a hash in forms.

Also, try adding a line underneath your validation:

$("#formapplication").valid();

3 Comments

Thanks Steerpike acutally i was missing class required on all my input
That's perculiar, as between your methodology and the documentation I had presumed that was intended behaviour. I assumed you were using the 'rules' option to bypass the class required
how i can use rules to bypass the class required ? would you please tell me i don't know i did't change rules but add required class to markup n it start woriking
0
  1. First, as Seb said, you need quotes around your field names.
  2. Second, as I understand the rules and messages hashes from the documentation, you need to refer to elements by the the name attribute, not the id attribute. So instead of "tb_catg": {required: true} I think you want "select": {required: true} since your HTML says <select name="select" id="tb_catg">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.