views:

24

answers:

1

I've the following script in my HTML:

jQuery.sundayMorning(text, { destination: 'en' }, function(response) {
    var uri = response.translation;
    var text = decodeURIComponent(uri);
    jQuery(".showText").val(text);
});

Example input in Spanish: la casa de leo el combatiente.

This translates into English as: leo's house fighter.

I want to show this as: leo's house fighter.

Anyone knows a way to solve this?

+1  A: 

Normally, you would use the element.html() function for this. But since you're using val(), you'll be trying to show it in an input element instead of some div. Input elements doesn't support the html() fuction. Since there's no direct API available in jQuery to decode HTML/XML entities, you'd like to create a div element, use its html() and then get the result as text().

var decodedText = jQuery("<div/>").html(encodedText).text();

Then you can show this in the input element.

jQuery(".showText").val(decodedText);
BalusC
Thanks BalusC!, that solved my problem.
mxm
You're welcome.
BalusC