I want to move my functions to a separate js file, but when I do it, they stop working. How to approach this problem? Are there some other syntaxes when you want to move the functions to a separate *.js file?
function edit_description() {
var targetDescription = $("#description-1");
var value = targetDescription.text();
if (value != "") {
value = ""
};
targetDescription.html(`<input class="description form-control" data-target="description-1" type="text" value=${value}>`);
$("input:text").focus();
$("input").blur(function (e) {
e.preventDefault();
var target = targetDescription.children('input').attr("data-target");
$(`#${target}`).text($(this).val());
var description = $(this).val();
save_description(identification = "description-1", description);
});
};
function save_description(identification, description){
console.log('Saved!');
var userInput = {"identification":identification, "description":description};
};
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
</head>
<body>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src=/static/main.js></script>
<div class="table-wrapper">
<table id="table" class="table table-striped">
<thead>
<tr>
<th scope="col"><span>Edit</span></th>
<th scope="col"><span>Description</span></th>
</tr>
</thead>
<tbody>
<tr>
<td id = "edit-1"><a class="btn" role="button" onclick="edit_description();">Edit ></a></td>
<td id = "description-1">Lorem</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
As you can see I put my js in a file called main.js in a static directory.