Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

jquery validation engine help

Posted on 2013-01-23
5
Medium Priority
?
817 Views
Last Modified: 2013-02-06
I am using Jquery ValidationEngine plugin to validate the form fields. I have the scenario when I have to validate the field that depends on the value of the hidden form variable. So the hidden variable is empty then I need the field above to required

<form id="testform" style="border:1px solid black; margin:2em; padding:1em;">
 <label for="source">Select2</label>
    <input type="text" name="txt" id="txt" class="validate[required]" value="here is my test">
    <br/>
   
<input type="hidden" name="txtHidden" id="txtHidden" value="">
    <br/><br/>
    <input type="submit" value="Submit" />
</form>

$(document).ready(function() {
    $('#testform').validationEngine();
});

or use link  
http://jsfiddle.net/mu93Y/4/
0
Comment
Question by:erikTsomik
  • 3
  • 2
5 Comments
 
LVL 83

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 38811834
by default don't add the class :
<input type="text" name="txt" id="txt" value="here is my test" />
And use :
$(document).ready(function() {
    if( $("#txtHidden").val() == "" ) $("#txt").addClass("validate[required]");    
    $('#testform').validationEngine();
});

Open in new window


test page : http://jsfiddle.net/mu93Y/6/

or do the same job on the server side
0
 
LVL 19

Author Comment

by:erikTsomik
ID: 38811921
that is not working. For example If I provide the value to txt it still submits even if there is not value in txtHidden

http://jsfiddle.net/mu93Y/10/
0
 
LVL 83

Expert Comment

by:leakim971
ID: 38811945
If you put something in txt you don't want to submit???
0
 
LVL 19

Author Comment

by:erikTsomik
ID: 38812248
I want only submit is there is a value txtHidden
0
 
LVL 83

Expert Comment

by:leakim971
ID: 38812313
$(document).ready(function() {
    $("form").submit(function(evt) { if( $("#txtHidden").val() == "" ) evt.preventDefault();  })
    $('#testform').validationEngine();
});

Open in new window

0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question