Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery val() does not work for textarea in Opera

I am displaying a modal dialog using jQuery. This dialog has a textarea control on it. But while submitting this dialog, the value of this textarea is not recognized by jQuery for some reason: it always comes blank. This works perfectly in other browsers. I put alert to display the value but it looks blank. Can anybody help me in this regards?

Controls:

<input type="text" id="txtGroupName"/>
<textarea rows="3" cols="30" id="txtDescription"></textarea>

jQuery code which used this value:

var postData = new Object();
postData.GroupName = $('#txtGroupName').val();
postData.Description = $('#txtDescription').val();

$('#txtDescription').val() comes blank but $('#txtGroupName').val() is read correctly as it is a input field.

One more finding about this issue:

When I put alert in my update function after populating the control value on page load, this alert displays the existing value properly. But it displays only existing value. It does not display the edited value after submitting the modal box.

like image 572
Anil Soman Avatar asked Sep 16 '10 05:09

Anil Soman


People also ask

How do I get textarea text in jQuery?

We can get the value of textarea in jQuery with the help of val() method . The val() method is used to get the values from the elements such as textarea, input and select. This method simply returns or sets the value attribute of the selected elements and is mostly used with the form elements.

What is $( This val () in jQuery?

jQuery val() Method The val() method returns or sets the value attribute of the selected elements. When used to return value: This method returns the value of the value attribute of the FIRST matched element.


3 Answers

I fix this using this in textarea

$("#descripcion").keydown(function(){
     $("#descripcion").css("display","block");
});

put at end of script. I am sorry for my english

like image 109
Javier Canizalez Avatar answered Oct 31 '22 07:10

Javier Canizalez


val() and text() in jquery works correctly, but after setting value of textarea you need to rerender textarea, you can do this setting css property in such way

if ($.browser.opera)
    $('textarea').val(someText).css({display:block});
else
    $('textarea').val(someText);

Hello from Russia. Sorry for my english =)

like image 24
egza Avatar answered Oct 31 '22 08:10

egza


Have you tried .attr("text") or .attr("value")? I'm unable to test this but this would seem logical to me.

If it doesn't then let me know and I'll remove this answer.

like image 1
griegs Avatar answered Oct 31 '22 07:10

griegs