Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Jquery Modal Form - Click twice

Status
Not open for further replies.

primagic

IS-IT--Management
Jul 24, 2008
476
GB
I have the following code that works by clicking the button once on a few pages but others I need to click twice.

Code:
<script type="text/javascript">
        /*
        * jQuery UI Dialog: Open Dialog on Click
                */
        $(function () {
            $("#dialog").dialog({
                autoOpen: false
            });
            $("#btnAddCustomer").on("click", function () {
                $("#dialog").dialog("open");
                
            });
        });
	</script>
 
I have the following code that works by clicking the button once on a few pages but others I need to click twice.

use a finite state machine to determine.

Code:
<script type="text/javascript">
        /*
        * jQuery UI Dialog: Open Dialog on Click
                */
        $(function () {
            var clickstate = 0;
            var clicktimer;
            $("#dialog").dialog({
                autoOpen: false
            });
            $("#btnAddCustomer").on("click", function () {
                if(clickstate == 1){
                	clearTimeOut(clicktimer);
                	clickstate = 0;
                	$("#dialog").dialog("open");
                } else {
                    clickstate = 1;
                    clicktimer = setTimeOut(function(){
                       	clickstate = 0;
                    }, 2000);
                }
                
            });
        });
</script>

there is also the double click event that you might want to look into. for that you would bind .on('dblclick',function()... make sure you do not bind both to click and dblclick on the same element (or within the same bubble)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top