0

I want to access the value of an attribute defined in the checkbox. The code of defining the checkbox is :

<input id="checkboxes" type="checkbox" name="item" class="row" statusid="10" value="175627">

This peice of code is inside a phtml file .

Now in my JS file,I want to access the attribute value for statusid i.e 10. How can I achieve this ?

Please refer below image for clear understanding. enter image description here

Thanks for reading.

3 Answers 3

3

Use .getAttribute():

document.getElementById("checkboxes").getAttribute("statusid")

-- View Demo --

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

3 Comments

Dangit, beat me to it. +1 :P
Hi, this has worked file. Thanks for it . But I am facing one issue. There are multiple check-boxes in my table which have diffrent status-id's associated with them. By using the above code, I am only getting the value of 1st checkbox. How can I get the values of all the checkboxes?
@Daffy You should have only one ID per element. Therefore give them all different IDs
0

You can use

var input = document.getElementById("checkboxes");
var statusID = input.getAttribute("statusid");

to get the attribute.

1 Comment

Hi, this also had worked fine. Thanks for it . But I am facing one issue. There are multiple check-boxes in my table which have diffrent status-id's associated with them. By using the above code, I am only getting the value of 1st checkbox. How can I get the values of all the checkboxes?
0

If you want to get the value of the statusid attribute:

Using jQuery:
$("#checkboxes").attr('statusid');

Pure Javascript:
document.getElementById('checkboxes').getAttribute('statusid');

If you want to get the value of input element that statusid attribute has value of 10 (will return 175627 for your example):

Using jQuery:
$("input[statusid='10']").val(); 

Pure Javascript:
document.querySelector("input[statusid='10']").value;

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.