Solved

Function not firing using .click

Posted on 2014-09-07
12
313 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
ID: 40308482
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
ID: 40308542
@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
ID: 40308543
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
ID: 40308617
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
ID: 40308796
not clear.
please answer this question : when do you want to see the freow-alert ?
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:peter-cooper
ID: 40312666
leakim971

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

Author Comment

by:peter-cooper
ID: 40312707
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
ID: 40312670
please post this "something different" to help the community
0
 

Accepted Solution

by:
peter-cooper earned 0 total points
ID: 40313920
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
ID: 40324953
I found my own solution and decided to drop this course and persue some other route.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to dynamically set the form action using jQuery.
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…

867 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

12 Experts available now in Live!

Get 1:1 Help Now