I am currently working on creating a form where selecting a radio button will change the href location of a button and open it in a JavaScript pop-up. The script I have for changing the href is as follows:
<script type="text/javascript">
<!--
// Retrieve the value of the checked radio button
// Return an empty string if none are checked, or if there are no radio buttons
function getCheckedValue(radioObj) {
if(!radioObj)
return "";
var radioLength = radioObj.length;
if(radioLength == undefined)
if(radioObj.checked)
return radioObj.value;
else
return "";
for(var i = 0; i < radioLength; i++) {
if(radioObj[i].checked) {
return radioObj[i].value;
}
}
return "";
}
// Set the radio button with the provided value as checked
// Do nothing if there are no radio buttons
// If the given value does not exist, all radio buttons are reset to unchecked
function setCheckedValue(radioObj, newValue) {
if(!radioObj)
return;
var radioLength = radioObj.length;
if(radioLength == undefined) {
radioObj.checked = (radioObj.value == newValue.toString());
return;
}
for(var i = 0; i < radioLength; i++) {
radioObj[i].checked = false;
if(radioObj[i].value == newValue.toString()) {
radioObj[i].checked = true;
}
}
}
//-->
</script>
For the pop-up functionality, I am using Highslide JS from highslide.com.
The form code I have implemented is:
<form name="radioExampleForm" method="get" action="" onsubmit="return false;">
<p><label for="number0"><input type="radio" value="popups/download1.html" name="number" id="number0"> Free</label>
<label for="number1"><input type="radio" value="popups/download2.html" name="number" id="number1">Premium</label>
<p>
<input type="button" onclick="return hs.htmlExpand(this, { objectType: 'iframe' } ); window.location.href = (getCheckedValue(document.forms['radioExampleForm'].elements['number']));" value="Download" class="button">
</form>
I am trying to merge these scripts together, but they don't seem to work when combined. Any insights on what could be going wrong?