tags:

views:

84

answers:

4

i have the following lines of html code -

 <div class="twitters" id="cbd">
          <p><a href="javascript:;" onClick="tweeet('<?php echo $c; ?>')">My Tweets!</a></p>
        </div>

Now what i need to do is call the tweet() javascript function without any link being clicked or any button being clicked . i.e this function is called on its own whenever the page is loaded.

+4  A: 

You can use the load event which fires when page has loaded:

<script type="text/javascript">
  window.onload = function(){
    tweeet('<?php echo $c; ?>');
  };
</script>
Sarfraz
that does not seem to be working. Actually for the correct working for the function it needs to be enclosed in those div tags whose class is "twitters"
ayush
Should be `onload`.
bobince
@bobince: Good catch, I have become more used to jquery these days :)
Sarfraz
@ayush: See the updated answer please.
Sarfraz
@ayush: do you want to call tweet function for each div with class twitters?
Soe Moe
@bobince,Sarfraz- thanks a lot. It had to be onload. working great now.
ayush
@Soe Moe - yes. thats what i want
ayush
@ayush: It is good news then...
Sarfraz
A: 

Maybe, you need this:

onClick="tweeet('<?php echo $c; ?>'); return false;"
tambourine
A: 

You can also set a Javascript event to run from time to time, if you want to do that, this link will be helpful for you: http://www.w3schools.com/js/js_timing.asp

Lajos Arpad
A: 

Maybe you've already solved the problem. I'm not sure, the question is not marked as answered.

That guy sAc answered your question. It can be called when the onload event is fired.

The function tweeet is probably just badly designed. It just doesn't make sense why would it needed to be enclosed in the div (especially when the div has its own id set).

Jan Kuča