I have the following HTML to give two radio button options. If the user selects one option and click submit, it will go to the corresponding page.
<script src="js/jump.js"></script>
<form onsubmit="jump()">
<input type="radio" name="querytype" value="apple">Go to Apple page<br>
<input type="radio" name="querytype" value="orange">Go to Orange page<br>
<input type="submit" value="OK">
</form>
In the JS file jump.js, I have the following function:
function jump() {
var selected = document.getElementsByName('querytype');
for(var i=0; i<selected.length; i++) {
var value = selected[i].value;
if (selected[i].checked) {
if (value === 'apple') {
window.location.href = '/myapp/apple-page';
} else {
window.location.href = '/myapp/orange-page';
}
}
}
}
But this is not working. When I make a choice and submit it, it doesn't go to either "Apple" or "Orange" page, but it shows a blank page. How do I make it happen?