1

I have a checkbox and a label for the checkbox that is actually coded as another field:

    <td style="text-align:left; width:210px; font-size:11px;
    height:20px;vertical-align:middle; " colspan="2" >
    <asp:CheckBox ID="Weaknessx" runat="server" AutoPostBack="false"/>
    <a style="color: black;text-decoration: none;" id="Weakness"
       href="javascript:void(0)" 
       onclick="addlinethrough(Weakness)"
       ondblclick="removelinethrough(Weakness)">Weakness</a>
    </td>

There are options for the user: click the checkbox / unclick the checkbox; click the label / unclick the label

When clicking the label the textDecoration is changed to line-through. When dblclicking the label the textDecoration is changed to none. This works fine.

What I want to do is when clicking the label to put line-through I also want to "uncheck" the checkbox. There are several similar fields so to do this with one set of javascripts I have named the labels and the checkboxes similarly. label id = "Weakness" checkbox id = "Weaknessx" The checkbox always has an appended "x".

This is my javascript which is not working. The checkbox is not getting unchecked.

function addlinethrough(elem) {
    elem.style.textDecoration = "line-through";
    document.getElementById(elem+x).checked = false;
    return false;
}
function removelinethrough(elem) {
    elem.style.textDecoration = "none";
    return false;
}

It appears to me that the checkbox id is not being recognized

0

1 Answer 1

1

If you want to append a string you need to use ticks and you need to get the ID, not the element itself:

document.getElementById(elem.id + 'x')

will work.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I knew it would be something simple.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.