1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Running Javascript inside Javascript?

Discussion in 'JavaScript' started by FPForum, Jan 12, 2012.

  1. #1
    What i am trying to do may sound kind of complicated but it really isn't. I currently have a form with two buttons (a 'yes' and 'no' button)..I want to run a small piece of javascript (the javascript for facebook share) randomly once out of every 10 times a user clicks yes or no on the form. It seams to me like I could have javascript to randomly display a message once out of every 10 button clicks - but not actually run a piece of javascript code like the facebook share code.

    Is this possible?
     
    FPForum, Jan 12, 2012 IP
  2. JohnnySchultz

    JohnnySchultz Peon

    Messages:
    277
    Likes Received:
    4
    Best Answers:
    7
    Trophy Points:
    0
    #2
    yes. just use a counter variable.. and it's not called running javascript inside javascript it's just javascript..



    
    
    <button onclick="doThis();">Click!</button>
    
    <script type="text/javascript">
    var clickCount = 0;
    
    function doThis()
    {
       clickCount++;
       if(clickCount >= 10)
       {
          // do you thing here...
    
          ...
    
          clickCount=0; // reset counter
       }
    }
    
    
    </script>
    
    
    HTML:
     
    JohnnySchultz, Jan 12, 2012 IP