I know jQuery is easy to get the value but how can i use Javascript only to get the value?
<input type="text" class="num" /> <a href="#" onclick="alert(document.getElementsByClassName('num').value);"> click </a>
thanks for help
I know jQuery is easy to get the value but how can i use Javascript only to get the value?
<input type="text" class="num" /> <a href="#" onclick="alert(document.getElementsByClassName('num').value);"> click </a>
thanks for help
document.getElementsByClassName returns an array of elements. You're looking for the first element in that array:
document.getElementsByClassName('num')[0].value;
i think the most common way to do that is give the element a "id" .... at least it's what i did when i was using javascript in old days before jQuery and all other JS frameworks.
<input id='mytext' type="text" class="num" />
and use this to capture:
document.getElementById('mytext');
so it will be:
<a href="#" onclick="alert(document.getElementById('mytext').value);"> click </a>