<input type="number" id="first" value=" "><button onclick=" myfunc()>closing tag> , how to take value of input length, | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

<input type="number" id="first" value=" "><button onclick=" myfunc()>closing tag> , how to take value of input length,

I want value of input element but directly as an argument of myfunc(length), for example, sometime we use myfunc(this.value), but now , since value belong to other tag, so how to take value of other tag in my example,

10th Jul 2017, 7:57 AM
ASHISH PANDEY
ASHISH PANDEY - avatar
2 Answers
+ 4
You can do: myfunc(this.parent.firstChild.value); ... or something like that, depending on the html context ^^ Anyway, this could becomes a little tricky, as some browsers considerate empty node text in child elements list, and other not :P So, safer to do something like: myfunc(this.parent.getElementsByTagName('input')[0].value); Or you can use window.queryQuerySelctor() to select your input with an absolute css path selector string, avoidind the use of 'this' ;)
10th Jul 2017, 8:55 AM
visph
visph - avatar
0
I do know getElement method, so except that..
10th Jul 2017, 7:58 AM
ASHISH PANDEY
ASHISH PANDEY - avatar