+ 2
Why doesn't work?
can anyone help me with this code i don't know why it doesn't answer it works in other situations but not here https://code.sololearn.com/WgeCW9MKel5Y/?ref=app
4 ответов
+ 4
function str2num(){
var inp = ""; // you could combine this line with the one below if you wish
inp = document.getElementById("input").value; // get the value not innerHTML also it is already a string no need to wrap in a function
var num = [65];
for(var i=0; i<inp.length; i++) // you had input.length instead of inp.length
num.push(inp.charCodeAt(i));
document.getElementById("demo").innerHTML = num;
}
+ 4
<input id="input" type="text">
<button onclick="str2num()">Click me</button>
innerHTML is a child of the element. Look at the button above. Click me is a textNode that is a child of the button tag. Try adding this code to the end of your function to output the buttons text:
alert(document.getElementsByTagName('button')[0].innerHTML);
Now look at input, it has no child, but if you put in the attribute value="something" and run the code again, you'll see that "something" is the text that is within the inputs textbox.
<input id="input" type="text" value="something">
+ 3
you've helped me a lot!
I've learned a lot
thanks👌👍👏
+ 1
tnx
value not innerhtml
what are the differences?