Forum Moderators: open

Message Too Old, No Replies

Can't correctly pass value to function

         

trapezechic

10:56 pm on Sep 7, 2010 (gmt 0)

10+ Year Member



I am new to javascript. Forgive me if this a dumb mistake...

I am trying to make a function that allows the user to click an image to set the radio button. I want to pass the value to the function from the onclick command to tell the function which radio button to set. It's not working. Here is my code:


<script>
function radioSelect(radioID) {
document.getElementById("radioID").checked = true;
}
</script>



<td><input name="room" type="radio" id="liveR" value="live" /><a href="#" onclick="radioSelect(liveR);"><img src="images/icon-live.jpg" width="50" height="60" /></a></td>

Fotiman

1:28 am on Sep 8, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Welcome to WebmasterWorld!

document.getElementById("radioID")
should be:
document.getElementById(radioID)

Since radioID is the variable that you want to find. Otherwise, you'll be searching for the element with the literal ID value of "radioID".

daveVk

3:24 am on Sep 8, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Also for the opposite reason your call to radioSelect needs to be.

onclick="radioSelect('liveR');"

that is the literal value 'liveR' NOT a variable named liveR.

Fotiman

1:22 pm on Sep 8, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yeah, good catch daveVk. :) I missed that.