How to pass value to label in modal

Asked

Viewed 525 times

2

I fill in the inputs of my modal as follows:

<input type="text" id="txtDescricao" name="txtDescricao" minlenght="4" required>   

Script:

modal.find('.modal-body input[name="txtDescricao"]').val(descricao)

And when I have a label, like:

<label for="teste"></label>

As a step the value of the variable description for him?

  • You need to use this modal.find not at the modal show event only makes $("#txtDescription"). val('VALOR_AQUI'); take a look -> http://jsfiddle.net/filadown/7ax1w7td/

2 answers

3


Just pass the delimiter in case the id of its input:

var novoLabel = $('#textoDescricao').val();
$("#teste").text(novoLabel);

So you wouldn’t use this "modal.find", just look for the element delimiter and pass it via jQuery.

In your case, for being a label use the .text() because it takes the text of your label and modifies it by the new value, if it was a input you should use the .val()

Follow a jsFiddle with the example: http://jsfiddle.net/wakeupmh/cmL9bdfa/

1

Try it like this:

$('.modal-body label').text(descricao)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.