+ 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

13th Sep 2017, 11:32 PM
Faramarz Monazami
Faramarz Monazami - avatar
4 Respostas
+ 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; }
14th Sep 2017, 12:01 AM
ChaoticDawg
ChaoticDawg - avatar
+ 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">
14th Sep 2017, 12:09 AM
ChaoticDawg
ChaoticDawg - avatar
+ 3
you've helped me a lot! I've learned a lot thanks👌👍👏
14th Sep 2017, 12:12 AM
Faramarz Monazami
Faramarz Monazami - avatar
+ 1
tnx value not innerhtml what are the differences?
14th Sep 2017, 12:02 AM
Faramarz Monazami
Faramarz Monazami - avatar