Results 1 to 3 of 3

Thread: onclick event requires 2 clicks

  1. #1
    Join Date
    Feb 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default onclick event requires 2 clicks

    i have button.js file which contains 2 fuction

    button.js
    Code:
    function displayclue()
    	{
    		
      $("#butt").click(function(){
        $("#clue").load('clue.txt');
      });
    return false;
    	}
    	
    	
    	
    function displayclue1()
    	{
    		
      $("#but").click(function(){
        $("#clue1").load('clue1.txt');
      });
    return false;
    	}

    and my html code is

    Code:
     <p id="clue1"> WANT CLUE CLICK HERE <button id="but" onclick="displayclue1()"> GET CLUE </button></p>p
        <br />
        <br />    
        <p id="clue">NEXT CLUE <button id="butt" onclick="displayclue()"> NEXT CLUE</button> </p>

    first button requires only one click while second button requires 2 click
    what is wrong with my code??i tried lot of things but no result
    thank you
    Last edited by akshay1728; 02-07-2012 at 01:33 PM.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    When you're using jQuery you don't need onclick events inline in your HTML. And one would assume that the Next Clue shouldn't be available until the First Clue is seen. So:

    Code:
    jQuery(function($){
    	 $("#but").click(function(){
    		$("#clue1").load('clue1.txt');
    		$("#butt").click(function(){
    			$("#clue").load('clue.txt');
    		}).attr('disabled', false);
    	});
    });
    and:

    Code:
    <p id="clue1"> WANT CLUE CLICK HERE <button id="but"> GET CLUE </button></p>
        <br />
        <br />    
        <p id="clue">NEXT CLUE <button id="butt" disabled> NEXT CLUE</button> </p>
    But, if you just want it the way it was, but working on a single click for each:

    Code:
    jQuery(function($){
    	 $("#but").click(function(){
    		$("#clue1").load('clue1.txt');
    	});
    
    	$("#butt").click(function(){
    		$("#clue").load('clue.txt');
    	});
    });
    and the HTML part, without the disabled:

    Code:
    <p id="clue1"> WANT CLUE CLICK HERE <button id="but"> GET CLUE </button></p>
        <br />
        <br />    
        <p id="clue">NEXT CLUE <button id="butt"> NEXT CLUE</button> </p>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Feb 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    it works, thank you very much
    god bless you

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •