...

View Full Version : What's wrong w/ this function?



ShadowIce
06-12-2010, 04:49 PM
I can't get the

function getchecked() to show

an alert box...



<script>
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 "";
}
}
function getchecked(){
var thecode=getCheckedValue(document.forms['radioExampleForm'].elements['code']);
if(thecode!==""){
if(thecode=="HTML"){
alert('Checked value is: '+thecode+'.');
//playSound("test1.mp3");
}else if(thecode=="PHP"){
//playSound("test2.mp3");
alert('Checked value is: '+thecode+'.');
}else{
//playSound("test3.mp3");
alert('Checked value is: nothing');
}
}
}
</script>

<label for="code1"><input type="radio" value="HTML" name="code" id="code1"> HTML</label>
<br><label for="code2"><input type="radio" value="PHP" name="code" id="code2"> PHP</label>
<br><label for="code3"><input type="radio" value="MySQL" name="code" id="code3"> MySQL</label>
<br><input type="button" onclick="getchecked()" value="Show Checked Value">

thanks!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum