joachim
joachim

Reputation: 692

Textarea Text not changing

I have 2 functions in my Javascript, the first one receives a JSon from an WebApi takes a string and writes that to a textare, than i change something in that textarea and submit it back to the server, when i select another object from a dropdown it should receive that JSon from the Api.

The following occurs what i find very strange, as long as i dont change anything in the textarea it works just fine receiving every item i want. The moment i change something in my textarea it doesnt change it anymore when i select another item in the Dropdown, neither does it change after i edited something in the text area without saving it back and select another item from the dropdown while the changes of the other values work just fine.

$.getJSON(uri + '/' + id).done(function (data) {                        
    $("#tarea").text(atob(data.xmlString));                                               
    document.getElementById("currentTicket").textContent = "Current Ticket: " + data.TicketID;
    document.getElementById("menu1").textContent = data.TicketID;
    document.getElementById("input").value = data.TicketID;
})

Upvotes: 3

Views: 1156

Answers (3)

Sajad Karuthedath
Sajad Karuthedath

Reputation: 15847

use .val() for all input types

and .text() for span tags

and for all other tags use .html()

So use

$("#tarea").val(atob(data.xmlString));

Upvotes: 2

Anik Islam Abhi
Anik Islam Abhi

Reputation: 25352

Convert this

$("#tarea").text(atob(data.xmlString))

to this

$("#tarea").val(atob(data.xmlString))

Upvotes: 2

Arun P Johny
Arun P Johny

Reputation: 388446

Use .val() set the value of text area instead of using .text()

$("#tarea").val(atob(data.xmlString));

Since you are using jQuery, you can use jQuery methods to set the text contents and value like

$.getJSON(uri + '/' + id).done(function (data) {
    $("#tarea").val(atob(data.xmlString));
    $("#currentTicket").text("Current Ticket: " + data.TicketID);
    $("#menu1").text(data.TicketID);
    $("#input").val(data.TicketID);
})

Upvotes: 7

Related Questions