Solved

jquery validation engine help

Posted on 2013-01-23
5
782 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 82

Accepted Solution

by:
leakim971 earned 500 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 82

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 82

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

910 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now