0

I've got this problem that I can't solve. Partly because I can't explain it with the right terms. I'm new to this so sorry for this clumsy question.

Below you can see an overview of my goal.

I'm running this code in Magento

<input type="checkbox" style="margin-left:24px" class="mydelete" name="checkAll" onclick='checkedAll(testCheck);' />
1
  • And I'm planning to get the property using class or name Commented Aug 26, 2013 at 5:48

4 Answers 4

2

Added an id attribute to the element.

<input type="checkbox" style="margin-left:24px" class="mydelete" name="checkAll" id="checkAll"onclick='checkedAll();' />

Javascript

function checkedAll(){
    if (document.getElementById('checkAll').checked) {
        alert("checked");
    } else {
        alert("You didn't check it! Let me check it for you.")
    }
}

DEMO

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

3 Comments

Thats why i mentioned it in my answer
Thanks for the reply I tried this one before only but its not working in side Magento
yeah Ofcourse its working their but in my code its not working also for this i tried document.getElementById,document.getElementByName,document.getElementByTagName
2

If you are flexible with using jQuery, you can easily do something like -

$("input:checkbox").is(":checked")

which will return a boolean value based on whether that input box is checked or not.

1 Comment

The question does not have a jquery tag.
2

You can do this using below code.

var checkprop = document.getElementsByName("checkAll").checked;
alert(checkprop);

EDIT

function checkedAll()
{
    var theform = document.theform;
    if(theform.checkAll.checked )
    {
        alert("checkAll Checked");
    } else {
        alert("Nothing Selected");
    }
}
<form name="theform">
    <input type="checkbox" style="margin-left:24px" class="mydelete" name="checkAll" onclick='checkedAll();' />
</form>

3 Comments

@thanks for the reply But its giving "undefined" in alert message & i forgot to say i am doing this in magento
Ofcourse this won't work because getElementsByName returns a collection of elements.
@Dipesh Parmar Really boss its its displaying same "undefined"
0

If you want to check if the checkbox is checked:

<script>
function displayResult()
{
var x=document.getElementById("checkboxid");
alert(x.checked);
}
</script>

and in your body:

<button type="button" onclick="displayResult()">Display value</button>

Comments

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.