I’m trying to create a webpage that has a few radio buttons and a link — but the link’s destination depends on which radio button you have selected.
Here’s a crude example I’m using:
[code=php]
<form>
<input type=”radio” name=”r1″ onClick=”window.bananas=’bananas.html'”>Bananas <BR>
<input type=”radio” name=”r1″ onClick=”window.apples=’apples.html'”>Apples <BR>
<input type=”radio” name=”r1″ onClick=”window.oranges=’oranges.html'”>Oranges <BR>
</form>
<a href=”javascript:;”
onClick=”if (window.apples)
window.location.href=window.apples;
return false”>Click here only if you selected apples.</a>
Ideally, the link will only take you to ‘apples.html’ if you selected the Apples radio button. Nothing should happen if you’ve selected the other two.
It seems to work fine…at first. But it turns out that if you select Apples at first, but then you switch to another fruit, and click on the link, it’ll still go to the ‘apples.html’ — despite the radio button being selected on something else.
Is there a better way to accomplish this?
Thanks for your help!