Solved

Function not firing using .click

Posted on 2014-09-07
12
311 Views
Last Modified: 2014-09-16
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
Comment
Question by:peter-cooper
  • 6
  • 4
12 Comments
 
LVL 82

Expert Comment

by:leakim971
Comment Utility
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
 

Author Comment

by:peter-cooper
Comment Utility
@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
 
LVL 82

Expert Comment

by:leakim971
Comment Utility
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
 

Author Comment

by:peter-cooper
Comment Utility
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
 
LVL 82

Expert Comment

by:leakim971
Comment Utility
not clear.
please answer this question : when do you want to see the freow-alert ?
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

by:peter-cooper
Comment Utility
leakim971

Sorry, but have abandoned this code in favour something different. Thanks
0
 

Author Comment

by:peter-cooper
Comment Utility
I've requested that this question be deleted for the following reason:

Have decided to code something different.
0
 
LVL 82

Expert Comment

by:leakim971
Comment Utility
please post this "something different" to help the community
0
 

Accepted Solution

by:
peter-cooper earned 0 total points
Comment Utility
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
 

Author Closing Comment

by:peter-cooper
Comment Utility
I found my own solution and decided to drop this course and persue some other route.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
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)

772 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now