If the planets only attract, then how can they stay in their orbit? Gravity is related to mass, and gravity is an attracting force on every body. Then what happens when bodies only attract each other..without repulsion they may strike the sun. I think there must be a repulsive force. 

Another question arises, if only attraction is there, then why does the moon rotate elliptically around the earth?

And Mars comes closer to earth after 3 years?
Gravity does not repel, but there is another "force" at work here. The angular momentum of the original protoplanetary disk is conserved. In other words, just because the cloud condensed into planets doesn't mean it is going to stop spinning. 

When we orbit artificial objects, we speed them up until they reach a velocity that sustains orbit--so again there is another force at work, just not gravity. Gravity keeps objects in orbit (rather than letting them fly off into space). Imagine if you spin a yo-yo around in the air. The tension of the string is like gravity, keeping the yo-yo in orbit, but if you let go of the string then the other "force" (its momentum) will cause it to fly off.

(Technically, momentum is not a force. It is the product of the mass and velocity of the system--a conserved quantity, but the object required a force to bring it up to that velocity. In the case of a planet, it is the astronomical forces that acted on the protoplanetary disk. In the case of the yo-yo, it was your applied force to spin it.)