Jump to content

Image as checkbox label problem


xn1

Recommended Posts

Hi all,

 

I'm using an image as a checkbox label and I'm having a strange problem. When you move the mouse over the image, the associated checkbox highlights (as it should). However, clicking the image does not select the checkbox and I can't figure out why. Is this function not possible?

Link to comment
Share on other sites

can you provide some code, I never used an image as a label but i bet it's possible.

 

-edit (2 minutes later ::) )and it is possible:

 

try this:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />       
        <link type="text/css" rel="stylesheet" href="css/style.css" />
        <title>image as label</title>
    </head>
    <body>
        <form action="" method="post">
            <label for="name"><img src="image/button.png" alt="" /></label>
            <input type="text" id="name" name="name" value="" />
        </form>
    </body>
</html>

 

edit- 2 Oh wait, a check box, you need to do that with javascript. something like on.click set value to check

Link to comment
Share on other sites

well i just tried this and it works, not sure if it's clean javascript, but that what the javascript forum is for:

good luck!!  ;)

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />       
        <link type="text/css" rel="stylesheet" href="css/style.css" />
        <title>image as label</title>

    </head>
    <body>
        <form action="" method="post">
            <label for="mycheckbox" onclick="document.getElemenstById.mycheckbox.checked = true;"><img src="images/button.png" alt="" /></label>
            <input type="checkbox" id="mycheckbox" name="mycheckbox" value="ON" />
        </form>
    </body>
</html>

Link to comment
Share on other sites

Is there no other way than Js? Seems strange that html will let the image be the label and highlight the checkbox when your over the image but it won't let you select it

as far as I know there is not, because you are changing the value of another element. Did it work for you? if so let me know.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.