Javascript set value of one field in others

Asked

Viewed 178 times

3

I have the following code below

<script type="text/javascript">
    function getValue() {
      var x = document.getElementById("NuJaneiro");

      document.getElementById("NuFevereiro").value = x.value;
    }
  </script>

 <td>
    <input type="text" style="width: 80px;" runat="server" id="NuJaneiro" value='<%# DecimalPontoVigula(Eval("Janeiro"))%>'
      name="NuJaneiro" onblur="getValue()" />
  </td>


  <td>
    <input type="text" style="width: 80px;" runat="server" id="NuFevereiro" value='<%# DecimalPontoVigula(Eval("Fevereiro"))%>'
      name="NuFevereiro" onblur="getValue()" />
  </td>

My idea is to take the value of one field and put in another as soon as the user leaves the first field, however, the value is not being passed and when Pure by the browser hangs the screen.

inserir a descrição da imagem aqui

  • Don’t make no mistake?

  • @Paulohdsousa, error is no longer giving the value is not being passed to the <input type="text" style="width: 80px;" runat="server" id="NuFevereiro"

  • No, don’t do that. Deleting comments is deleting history. Where’s the answer that worked? In the @Laerte comment, I don’t see any link to a fiddle or anything like that.

  • @pnet he posted the answer.

  • 1

    the comment was by the comment, but after I posted is what I saw. I thought he had posted a link to a fiddle or etc and was not appearing to me. But thanks and success there.

1 answer

3


In Web Forms the default ID is generated dynamically.

Change the property Clientidmode for Static for this not to occur and remain the ID you have set.

<asp:TextBox runat="server" ID="NuJaneiro" ClientIDMode="Static" />
  • In this case I can’t define as Static, but, gave the idea of how I get the rendered id.

  • It’s just that I’m not with VS here, but if memory serves, the default is formName:idElement right?

  • BodyContent_livCamposForm_NuJaneiro_4 . are several fields created by the fact that this within a ListView

Browser other questions tagged

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