Jump to content

radio button image


Calamier
 Share

Recommended Posts

I was wondering, i've been doing some reading trying to get rid of a particularly pesky problem, im trying to have an image activate a radio button that corresponds to it, I was reading THIS URL and i was hoping someone could clarify this for me a bit, is the IMAGE the element, or is the radio button the element? could you provide an example i could expand upon, please?

Link to comment
Share on other sites

The onclick in the post refers to whatever element you want to control the radio input.So it could be an image, span, div etc.This example uses an image:

<html>  <head>  <title></title>  <script type="text/javascript">  function pickRad(field, i){  var radioGroup = document.forms[0].elements[field];    radioGroup[i].checked = true;   }  </script>  </head>  <body>    <form>            <input  type="radio" name="folders" value="1">      <img src="http://w3schools.invisionzone.com/style_images/1/f_norm.gif"         onclick="pickRad('folders', 0)" alt="New Posts" border="0">       <br>      <input  type="radio" name="folders" value="2">      <img src="http://w3schools.invisionzone.com/style_images/1/f_norm_no.gif"           onclick="pickRad('folders', 1)" alt="No New Posts" border="0">       <br>      <input  type="radio" name="folders" value="3">      <img src="http://w3schools.invisionzone.com/style_images/1/f_hot.gif"           onclick="pickRad('folders', 2)" alt="Hot Topics" border="0">           </form>  </body></html>

The radio buttons are indexed as a group( like an array ) so the first's index is 0.Let us know if you have questions.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...