I am working on an asp.net mvc application. I need to know how to use global javascript variables inside html code. I know global variables are not an ideal solution to a problem but for my solution to work I need them.
I know about their declaration. Here is an example of how I want to use them. I want to use the global js variable to be already filled in at the input.
var title;
function foo(b) {
title = b;
};
<input type="text" value=title readonly>
Any help will be appreciated. Thanks.
titleinto the input's attributevalue? if so, you didn't call that function as well as you're only setting a string "title" to the attribute value.id="my-input". Then from the JavaScript global scope you may usedocument.getElementById('my-input').value = title;