Forum Moderators: open
<html>
<head>
<title>Example</title>
</head>
<body>
<form action="">
<div>
<input type="radio" name="whereto" value="red-widgets">redwidgets
<input type="radio" name="whereto" value="blue-widgets">bluewidgets
<input type="button" id="submitBtn" value="Submit">
</div>
</form>
<script>
var submitBtn = document.getElementById('submitBtn');
submitBtn.onclick = function () {
// this = submitBtn
var i,
f = this.form,
n,
url = 'http://www.widgets.com/search.aspx?',
val = '',
whereto = f.whereto;
for (i = 0, n = whereto.length; i < n; i++) {
if (whereto[i].checked) {
val = whereto[i].value;
break;
}
}
url += val;
alert(url);
};
</script>
</body>
</html>
I get the alert box but it doesn't send the browser to
What if you wanted to combine multiple radio buttons together to further refine the query, is that possible?
<form action="vehicle_type">
<div>
<input type="radio" name="whereto" value="car">car
<input type="radio" name="whereto" value="suv">suv
<input type="radio" name="whereto" value="truck">truck
<input type="radio" name="whereto" value="van">van
</form>
<form action="vehicle_color">
<input type="radio" name="whereto" value="green">green
<input type="radio" name="whereto" value="red">red
<input type="radio" name="whereto" value="black">black
<input type="radio" name="whereto" value="yellow">yellow
</div>
</form>
<input type="button" id="submitBtn" value="Submit">
<script>
var submitBtn = document.getElementById('submitBtn');
submitBtn.onclick = function () {
// this = submitBtn
var i,
f = this.form,
n,
url = 'http://www.widget.com/search.aspx?find=',
val = '',
whereto = f.whereto;
for (i = 0, n = whereto.length; i < n; i++) {
if (whereto[i].checked) {
val = whereto[i].value;
break;
}
}
window.location = url + val;
};
</script>
<form action="http://www.widget.com/search.aspx" method="GET">
<div>
<input type="radio" name="vehicle_type" value="car">car
<input type="radio" name="vehicle_type" value="suv">suv
<input type="radio" name="vehicle_type" value="truck">truck
<input type="radio" name="vehicle_type" value="van">van
</div>
<div>
<input type="radio" name="vehicle_color" value="green">green
<input type="radio" name="vehicle_color" value="red">red
<input type="radio" name="vehicle_color" value="black">black
<input type="radio" name="vehicle_color" value="yellow">yellow
</div>
<input type="submit" id="submitBtn" value="Submit">
</form>