Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Redirect to another page when radio button clicked

Status
Not open for further replies.

bobrivers2003

Technical User
Oct 28, 2005
96
GB
HI,

I have a simple form consisting of two radio buttons. When a radio button is clicked the user is redirected to a given url.

Javascript:

function radio_input(url)
{
// Re-direct the browser to the url value
window.location.href = + url
}

Form:

<form id="form" method="get">
<input type="radio" name="group1" value="off" onClick="JavaScript:radio_input('<input type="radio" name="group1" value="off" onClick="JavaScript:radio_input('</form>


As you can see in the onClick"" you have to put the entire url as an argument. I want to just put the particular page (i.e JavaScript:radio_input('page2.php')

I tried removing the href from the javascript but just get an NaN error.

Any suggestions would be greatly appreciated.

Thanks and Regards
 
What's that +-sign doing in your JavaScript function? Is that really there or just a typo from when you posted your question? If it's there, remove it. Are these pages located on the same domain as the page with this code?

Dave

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...east is east and west is west and if you take cranberries and stew them like applesauce
they taste much more like prunes than rhubarb does
[infinity]
 
You mean something like this?

Code:
function radio_input(url)
{
// Re-direct the browser to the url value
window.location.href =  [COLOR=red]'[URL unfurl="true"]http://www.site.com/'[/URL] [/color] + url 
}

Form:

<form id="form" method="get">
<input type="radio" name="group1" value="off"  onClick="JavaScript:radio_input('page1.php')">
<input type="radio" name="group1" value="off"  onClick="JavaScript:radio_input('page2.php')">
</form>

Paranoid? ME?? Who wants to know????
 
And you don't need to put JavaScript: in the onClick event handler. With the capitalization, it might choke on that, but I'm not sure. Javascript is case sensitive, so capital and lower case letters mean completely different things.

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top