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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

go to page based on option checked

Status
Not open for further replies.

clientuser

Programmer
Apr 18, 2001
296
0
0
US
i have two radio buttons and a submit button on a form.

i want it so that when the user selects one of the radio buttons and pushes the submit button, it will take them to the page based on the radio button selected.

the javascript code i came up with is:

Code:
function checkradio(){
if (request.getParameter("R1").equals("V1")) {
 response.redirect "subscribe.asp"
 error=1;
 return false;

 }
else
if (request.getParameter("R1").equals("V2")) {
 response.redirect "unsubscribe.asp"
 error=1;
 return false;
}
else
  return true;
}

but i am just learning javascript .......

any suggestions?
 
Here's an example. You should be able to implement the function in the code below with no problems...

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
	<title>Untitled</title>
<script language="javascript">
<!--
function redir() {
	var the_loc = '';
	for (var i = 0; i < document.the_form.radio1.length; i++) {
		if (document.the_form.radio1[i].checked) {
			the_loc = document.the_form.radio1[i].value;
		}
	}
	document.location.href = the_loc;
}
-->
</script>
</head>

<body>
<form action="" name="the_form" id="the_form">
<input type="radio" name="radio1" value="[URL unfurl="true"]http://www.google.com/">Google<br>[/URL]
<input type="radio" name="radio1" value="[URL unfurl="true"]http://www.yahoo.com/">Yahoo!<br>[/URL]
<input type="button" name="go_there" value="Go" onclick="redir();">
</form>

</body>
</html>

Hope this helps...

*cLFlaVA
----------------------------
A pirate walks into a bar with a huge ship's steering wheel down his pants.
The bartender asks, "Are you aware that you have a steering wheel down your pants?"
The pirate replies, "Arrrrr! It's driving me nuts!
 
can you use selectedIndex for radio buttons? if so, you can make this even shorter

--Chessbot
 
Nope. selectedIndex is only for SELECT objects.

*cLFlaVA
----------------------------
A pirate walks into a bar with a huge ship's steering wheel down his pants.
The bartender asks, "Are you aware that you have a steering wheel down your pants?"
The pirate replies, "Arrrrr! It's driving me nuts!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top