Solved

jquery validation engine help

Posted on 2013-01-23
5
798 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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)
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…

733 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