Solved

Function not firing using .click

Posted on 2014-09-07
12
315 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
The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

 

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
 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
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…

837 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