Solved

jquery validation engine help

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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Open iframe using jquery dialog box 13 37
jQuery Toggle & Anchor Links 5 43
HTML Anchor Link Problem 3 35
How to control cache of some js files ? 7 39
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
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…

839 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