javascript - Why it is not printing the character in a paragraph? -
write script inputs integer code character , displays corresponding character.
it should print in paragraph.
function character() { var input = document.getelementbyid( "input" ); var code = document.getelementbyid( "output" ).innerhtml = input; output.value = string.fromcharcode( code ); }
<input id="input" type="text" size="10"> <br> <input type="button" value="click here" onclick="character()" id="button"> <br> <p id="output" ></p>
a p
not form element. if use form.fieldname, need use name=""
instead of id=""
; otherwise use document.getelementbyid
fields , ignore form.
you need use innerhtml or innertext/textcontent paragraph
document.getelementbyid("output").innerhtml=...
function character() { var form = document.getelementbyid("form"); var code = parseint(form.input.value,10); // radix 10 make decimal document.getelementbyid("output").innerhtml = string.fromcharcode(code); }
<form id="form"> <input name="input" type="text" size="10"> <br> <input type="button" value="click here" onclick="character()" id="button"> <br> <p id="output" ></p> </form>
Comments
Post a Comment