How redirect the url main domain to subdomain using javascript

I developing one website like quikr.com. In mysite i list out city list then while click the city its goes to subdomain like cityname.mywebsite.com. so how to achieve this using javascript. so share your ideas and suggestions.

Sounds like you don’t need JS. Just click it and go to the site. If you need different then you will have to explain it that way.

Thanks for reply. I am developing one classifieds site so i want know structure like, while click location it goes to subdomain(chennai.mydomain.com) and display contents regarding subdomain. so i created subdomain for all cities and redirect to cityname.mydomain.com. i am in struggle in landing page of after loading subdomain url because it shown individual page for each subdomain. share your ideas and suggestion.

I’m sorry. Tried as I might. I couldn’t understand the question again.