Selections and radioing - JavaScript

Posted by Wayne on Stack Overflow See other posts from Stack Overflow or by Wayne
Published on 2010-05-25T22:17:27Z Indexed on 2010/05/25 22:21 UTC
Read the original article Hit count: 197

Filed under:
|
|
|
|

I have a list like this:

<ul>
    <li id="adm-thumb" onclick="javascript:addBanner('bowling.jpg');">
     <div class="adm-tick"></div>
       <img src="img/banners/bowling.jpg" /></li>

    <li id="adm-thumb" onclick="javascript:addBanner('kcc.jpg');">
     <div class="adm-tick"></div>
       <img src="img/banners/kcc.jpg" /></li>

    <li id="adm-thumb" onclick="javascript:addBanner('paintballing.png');">
     <div class="adm-tick"></div>
       <img src="img/banners/paintballing.png" /></li>
</ul>

<input id="bannername" type="text" />

When one item is clicked, the value inside the addBanner() will be added to the input field, however, I want one list to be selected (which is done by css to make it look like it has) when it is equal to the value of the input value. If the value is equals to the value in the addBanner value then the clicked item should have a red background.

e.g.

function addBanner(label)
{
 var Field = document.getElementById('bannername');
 Field.value = label;

 if(Field.value != label)
 {
     // I have no idea what to put here
 }
}

Something like a div button that acts like a radio button.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about html