I am building a small tool to generate a copy and paste HTML block, based on the user inputs.
In the HTML file, I have all my inputs (select, checkbox, text inputs etc).
I based myself on the JS of an existing tool on the web, which has the following form. Everything works, but I wonder if there is an opportunity to improve or simplify the code.
(function( $ ) {
$(function() {
var a;
var b;
var c;
function updateHtml() {
a=$('#inputA').val();
b=$('#inputB').val();
c=$('#inputC').val();
html = '<div><p>My name : '+a+'</p><p>My phone : '+b+'</p><p>My mail : '+c+'</p></div>';
$('#code').html(html);
}
$( document ).ready(function() {
updateHtml();
});
$( "input" ).on('change',function() {
updateHtml();
});
});
})(jQuery);
The code seems unstructured to me. It works without prior declaration of variables
var a;
var b;
var c;
Inside the main function
(function( $ ) {})(jQuery);
There is a first function that allows me to retrieve the value of inputs and display the HTML bloc
Then a function to execute the update function when document is ready and finally a function to execute the update function when the inputs are changed..
The code works, but isn't there a more academic or logical way to build it?
Any help is appreciated.
a
,b
andc
there do not appear to be assignments for$inputA
,$inputB
and$inputC
… \$\endgroup\$