Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
HTML
<input style="width: 100%;" name="DateLead_DateEnd" id="DateLead_DateEnd" data-role="datepicker" type="text" class="k-input" role="combobox" aria-expanded="false" aria-owns="DateLead_DateEnd_dateview" aria-disabled="false" aria-readonly="false" aria-activedescendant="f8253ffd-a272-44a8-ba91-6a36b7b536b3_cell_selected">


What I have tried:

I have tried using getAttribute method but it gives error in browser
Posted
Updated 30-Jun-16 3:08am
Comments
Sergey Alexandrovich Kryukov 28-Jun-16 10:02am    
What have you tried so far?

Yes, it can be easily done via getting attribute, if you have a control reference, but it defeats the purpose of "id". Normally, id is used in JavaScript as input data, to find a control.

—SA
Richard Deeming 28-Jun-16 12:14pm    
When you get an error, you need to tell us what that error is.

We can't see your screen, so if you don't tell us, we don't know.

1 solution

I think, if you will access through element name or class (if it is unique), then you can get the id.

// Only when the name is unique for this element
var inputs = document.getElementsByName("DateLead_DateEnd");
alert(inputs[0].id);


OR

// Only when class name is unique for this element
var inputs = document.getElementsByClassName("k-input");
alert(inputs[0].id);


Hope, this will help you.
 
Share this answer
 
v3
Comments
Richard Deeming 30-Jun-16 9:33am    
getElementsByTagName needs the tag name ("input"), not the value of the name attribute.
Element.getElementsByTagName() | MDN[^]
Prava-MFS 30-Jun-16 9:40am    
Thanks @Richard for the catch. It should be 'getElementsByName' and the id can be accessed then as 'inputs[0].id'. Thank you for pointing it out :).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900