?
Solved

Function not firing using .click

Posted on 2014-09-07
12
Medium Priority
?
322 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
CHALLENGE LAB: Troubleshooting Connectivity Issues

Goal: Fix the connectivity issue in the lab's AWS environment so that you can SSH into the provided EC2 instance.  

 

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

WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

Question has a verified solution.

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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…
Suggested Courses

777 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