i want to know why this error is occuring \"Uncaught TypeError: Cannot read property \'value\' of null\" and where i am going wrong?
function create()
You should modify the function like so, for it to work. If you want to use setAttribute then you will have to wrap it in a function for the onBlur event
function create() {
var textbox = document.createElement("input");
var para = document.createElement("p");
para.setAttribute("id", "p");
textbox.type = 'text';
textbox.value = 'asdf';
textbox.setAttribute("id", "textbox");
textbox.setAttribute("onblur", function() {
para.innerHTML = textbox.value;
});
document.body.appendChild(textbox);
}
Or you can checkout the jsfiddle, to see how it works.
It was recommended to check in a previous answer, if the element is null, but in this case it's not needed as you are creating all the elements in the functions, so all elements will exist.
Also what do you plan to do with the paragraph element? Maybe wrap the input in the paragraph?
If you want you can add the paragraph simply by adding
document.body.appendChild(para);