What I'd like to do is have a check beside a link. If the box is checked, the user will be taken to page A. If unchecked (default) the user will be taken to page B.
Can javascript be used to do this?
| SitePoint Sponsor |

What I'd like to do is have a check beside a link. If the box is checked, the user will be taken to page A. If unchecked (default) the user will be taken to page B.
Can javascript be used to do this?
<a href="javascript://" onclick="if(document.forms['form_name'].elements['checkbox_name'].checked)window.location.href='pageA.html';else window.location.href='pageB.html'">
Use that as your link.![]()

Much cleaner than what I was working on just now...
What is the '://' for in the href tag?
- Mike
http://www.georgiaoffroad.com
href="javascript://"
Tells the browser to do nothing when the href is activated.
Also familiar ways of doing that is:
href="#"
href="javascript:void(null)"
href="javascript:void(0);"
And so on.

With your example the user is automatically taken to the next page when the checkbox is selected.
What I'm going for is to have the user select the checkbox, but only when the corresponding link is clicked will the script run.
That sounds awfully vague without seeing what I'm doing...
O TEXTLINK
When the TEXTLINK is clicked without a check in the O (checkbock), it fowards the user to ONE.HTM.
Conversly, if the checkbox 'O' beside TEXTLINK is selected, when the user clicks TEXTLINK he is taken to TWO.HTM.
No action should occur when the checkbox is selected in and of itself. The user must click the TEXTLINK for any action to take place.
- Mike
http://www.georgiaoffroad.com
It will not go automatically, you must have used it wrong. Use this:
<form name="red"><input type="checkbox" name="bla" /></form> <a href="javascript://" onclick="if(document.forms['red'].elements['bla'].checked)window.location.href='pageA.html';else window.location.href='pageB.html'">Something</a>
Bookmarks