Javacript Tweak

Posted on 2012-09-12
Medium Priority
Last Modified: 2012-09-26

I'd appreciate some help with tweaking a javascript validation script --

function validateBrandRate(formNode){
  var formValidatorInstance = new FormValidator(formNode);
  formValidatorInstance.addRule('nextyearreason','Please indicate why you will not deal with this brand next year','required');
  return formValidatorInstance.validate(); 

Open in new window

I need the script to run only if a checkbox with an ID of sliderLabel is checked.

At the same time, if the checkbox with an ID is checked I need the select with an id of nextyearreason to be enabled; and disabled if the checkbox is not checked.

I think this is two different scripts, an alteration to the first one and a new script for the enable disable.

Thank you
Question by:garethtnash
LVL 60

Accepted Solution

Julian Hansen earned 2000 total points
ID: 38390558
Take a look at the docs here http://docs.jquery.com/Plugins/Validation/validate#code

Specifically this section:
Specifies a contact element as required and as email address, the latter depending on a checkbox being checked for contacting via email.
   rules: {
     contact: {
       required: true,
       email: {
         depends: function(element) {
           return $("#contactform_email:checked")

Open in new window


Author Closing Comment

ID: 38437957
Thank you

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

840 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