Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5980113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:45:19+00:00 2026-05-22T21:45:19+00:00

Fairly basic question i’m hoping. In the following javascript, I want to run the

  • 0

Fairly basic question i’m hoping. In the following javascript, I want to run the checkval() function as if it were executed in the scope of which “this” (within the checkval) refers to the element that the plugin is being called on (well, one of the elements).

So if i called

$('.has_hidden').conditional(); 

Then that would run the checkval on all those items as well as binding it to the on change event.

Reason is, I have a form, which will unhide further options if you type in something, say if you type in “australia” it will unhide a bunch of other elements. Now when I save and reload that form, my php script repopulates the data, but the other elements remain hidden. I just need to run check val so they get un hidden. Ming Bai Ma

/**
 * This class will show or hide a bunch of elements (A,B,C) based on the value in element (E, this).
 * To use it, take the name of the form element (E, this) and apply it as a class to A,B,C
 * Then add a display none to A,B,C (add class off)
 * Set the "rel" tag on 
 * Finally, run $(E).conditional();
 */
(function( $ ){
    $.fn.conditional = function() {
    return this.each(function(){
        var $this = $(this);
        $this.unbind('change.cns').bind('change.cns', checkval);
    });
    function checkval(){
        var regex = $(this).attr('rel');
        var class_name =$(this).attr('name');
        if($(this).val().search(regex)>-1) 
        $('.'+class_name).show();
        else
        $('.'+class_name).hide();
    }   
    };
})( jQuery );
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T21:45:20+00:00Added an answer on May 22, 2026 at 9:45 pm

    Sorry I didn’t explain my question properly, but what I was actually looking for was

    $this.trigger('change.cns');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a fairly basic question, which for some reason, a proper solution escapes
this question should be fairly basic. I want to control the flow of an
Ok, this is a fairly basic question: I am following the SICP videos, and
This may seem like a fairly basic question, for which I apologise in advance.
Hey I have a fairly basic question about regular expressions. I want to just
This is a fairly basic question, but I haven't been able to find any
This is a fairly basic question about state server but assume there are 2
I am making a webapp. I have a fairly basic question about javascript performance.
All, This would seem like a fairly basic asp.net question - but in all
This is a fairly basic question, I currently have two tables and in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.