Retrieve a hidden value in html

2

I have a hidden attribute, which I put through a java method:

<input type="hidden" id="url" th:value="${url}" />

And I want to put an input of type text whose value will be the value that is in the hidden "url"

<input type="text" id= "textUrl" name="url" th:value="${url}" readonly="readonly" style="visibility:visible;"/>

But it gives me problems, since it never shows the URL value but instead it shows a text box that is always empty. I guess the problem will be in the form of passing the value to him but I do not see it ...

    
asked by cucurril 14.04.2016 в 12:12
source

1 answer

4

If the hidden field works correctly, the problem is when the page is mounted, the ${url} value is empty and it is set to textUrl , that's why you have the white text, then it changes, but it is not updated.

What I would do is an event so that when the value of the hidden field is updated, the other is also updated:

$( "#url" ).change(function() {
  $("#textUrl").val($("#url").val());
});

See this example in fiddle with something similar but using keyup to make the password display field, as You are writing in the input type="password" the input type="text" is updated.

    
answered by 14.04.2016 / 12:50
source