gtludwig gtludwig - 5 months ago 13
Javascript Question

javascript - what's wrong with this JS?

I have the following inputs:

<input class="form-control sampleLink" type="text" id="url" th:field="*{url}" th:value="*{url}" />
<input class="form-control sampleLink" type="number" id="port" th:field="*{port}" th:value="*{port}" />
<input class="form-control sampleLink" type="text" id="folder" th:field="*{folder}" th:value="*{folder}" />


I expect the next one to be auto-filled:

<input id="sampleLink" class="form-control" type="text" name="sampleLink" th:disabled="true" />


With this code:

<script type="text/javascript">
$().ready.(function() {
$(".sampleLink").change(function() {
var url = $("#url").val();
var port = $("#port").val();
var folder = $("#folder").val();

$("#sampleLink").val('http://' + url + ':' + port + '/' + folder + '/*.txt');
});
});
</script>


But I get no result. What am I missing?

Answer

You forgot }); in the end of function. Try this:

$(".sampleLink").change(function() {
var url = $("#url").val();
var port = $("#port").val();
var folder = $("#folder").val();

$("#sampleLink").val('http://' + url + ':' + port + '/' + folder + '/*.txt');});