You first have to create an ID for your input, assign it to a variable:
var element = document.getElementById("inputConcatenar");
Then you assign to the name
a new value, in which case I used the Replace that will search for a string that you pass and replace with another.
element.name = element.name.replace("strConcatenada", strConcatenada)
console.log(element.name);
I made it as simple as possible, the result is this, follows the console.log
name. If you want to remove the "<% %>" just pass <%strConcatenated%> to the Replace , getting like this:
replace("<%strConcatenada%>", strConcatenada)
<input id="inputConcatenar" type="hidden" name="<%=strConcatenada%>W_TESTE_AUTO" value="1">
<script type="text/javascript">
var strConcatenada = "STR_VARIAVEL.";
var element = document.getElementById("inputConcatenar");
element.name = element.name.replace("strConcatenada", strConcatenada)
console.log(element.name);
</script>
What is this template language?
– Sergio
@Sergio this example would be in an html page
– P. Dominges
Okay, and where does it come from
<%=
? are using some template-engine?– Sergio
Just this is my doubt, I looked for some examples and saw that used this format
<%=
to present variablesjavascript
, but I really didn’t succeed in this way– P. Dominges
Leonardo’s answer already explains how you can do it. Regarding this syntax
<%=%>
this is used in templates. Often on the server. But now I realize you don’t know what it is, so you can take it out of the question because it only confuses :)– Sergio