Solved

jquery validation engine help

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
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)

743 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

12 Experts available now in Live!

Get 1:1 Help Now