Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 327
  • Last Modified:

Function not firing using .click

I am trying to fire a function on a click event using $(this) perhaps to capture the event and fire a function. I have tried various methods, nothing seems to work. I would be grateful if someone could show me the correct way. Many thanks



$(function() { 
$("#box_frtv").chosen({

 width: "250px",
 max_selected_options: 1

 });
 $("#box_frtv").bind("chosen:maxselected",

            // Only want this function to fire onclick event. something like $(this).click( 
            function() {

            $("#boxerror").freeow("ERROR", "sample error message", {
                classes: ["gray", "error"],
                autoHide: true
            });
          });
        }); 

Open in new window

0
peter-cooper
Asked:
peter-cooper
  • 6
  • 4
1 Solution
 
leakim971PluritechnicianCommented:
why did you choose the chosen:maxselected event ?
check this page : http://jsfiddle.net/yytcqvho/

$(function() {

    $("#box_frtv").chosen({
         width: "250px",
         max_selected_options: 1
    
    });

    $("#box_frtv").on("chosen:hiding_dropdown", function() {
        $("#boxerror").freeow("ERROR", "sample error message", {
            classes: ["gray", "error"],
            autoHide: true
        });
    });

}); 

Open in new window

0
 
peter-cooperAuthor Commented:
@leakim971
Thanks for reply. However, your answer is not what I am trying achieve. Because I am using multiple, if a user selects more than 1 item from the list, this event is fired. User selects one item, clicks again to select another, event fired. Hope that is clearer. Many thanks
0
 
leakim971PluritechnicianCommented:
no, it's not clear
you want to fire the event ONLY if the user CURRENT selection have more than one after its last selection, right?
0
Industry Leaders: 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!

 
peter-cooperAuthor Commented:
Ok. firstly, I am using plugin from http://harvesthq.github.io/chosen/. You have the ability to set how many items the user can select in multiple mode. So, if a user selects more than 1 item, hence "chosen:maxselected" in my original code. That is working well. So, if a user clicks in the input and tries to select another, the function is fired, or an alert. I am using a notification plugin that is also working, but what is happening, is that when the user clicks the notification is displayed and also fires when the user unclicks. I figured that if I used a click event, this would eliminate this problem. Hope that helps. thanks
0
 
leakim971PluritechnicianCommented:
not clear.
please answer this question : when do you want to see the freow-alert ?
0
 
peter-cooperAuthor Commented:
leakim971

Sorry, but have abandoned this code in favour something different. Thanks
0
 
peter-cooperAuthor Commented:
I've requested that this question be deleted for the following reason:

Have decided to code something different.
0
 
leakim971PluritechnicianCommented:
please post this "something different" to help the community
0
 
peter-cooperAuthor Commented:
The reason that I haven't posted solution because there isn't one at the moment. I am trying to find an alternative way to approach this. If and when I find an alternative, I shall post it for the community. If it helps however, there is a solution to my original question and I shall post it here to try to help others. Thanks

$(function() { 

$("#box_frtv").chosen({

 width: "250px",
 max_selected_options: 1

 });
 var $boxerror = $("#boxerror");
 $("#box_frtv").bind("chosen:maxselected", function () {
        
        if($boxerror.find('.gray.error').length === 0){
            $boxerror.freeow("Retreival error", "Only 1 box can be selected . Thank you.", {
                classes: ["gray", "error"],
                autoHide: true
            });
        }
    });
});

Open in new window

0
 
peter-cooperAuthor Commented:
I found my own solution and decided to drop this course and persue some other route.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now