on select radio, redirect to a link

Anju Thapa picture Anju Thapa · Dec 30, 2011 · Viewed 12.2k times · Source

I have three radios and i want onselect of anyone to be redirected to a link. Using javascript or jquery

    All <input name="EventRadio" type="radio" value="" checked="checked"/>&nbsp;
    Events<input name="EventRadio" type="radio" value="Events" />&nbsp;Classes<input name="EventRadio" type="radio" value="Classes"/><br /><br />

so since "All" is default checked, i want it to go to mysite.com/search.aspx. now if user selects Events, I want to redirect user to mysite.com/search?type=Events or if user selects Classes, I want to redirect the user to mysite.com/search?type=Classes as response to the onselect of the radios. How do I achieve this?

Answer

Ramesh Kotha picture Ramesh Kotha · Dec 30, 2011
All     <input name="EventRadio" type="radio" value="" checked="checked" onclick ="goToLocation(this.value)"/>&nbsp;
Events  <input name="EventRadio" type="radio" value="Events" onclick ="goToLocation(this.value)"/>&nbsp;
Classes <input name="EventRadio" type="radio" value="Classes" onclick ="goToLocation(this.value)"/><br /><br />


function goToLocation(val){
 if(val == "Events")
     window.location = "go to Events location";
 if(val == "Classes")
     window.location = "go to Classes location";
window.location = "go to default location";

}