tags:

views:

350

answers:

6

This syntax for some reason isn't working and I'm wondering why. When I alert the values in the page, I can see everything but the textarea value. I'm not even getting an undefined.

var report  = $("textarea#report").val();


Here is my html:

<textarea id="report" name="report" rows="25" cols="10" style="width:100%;height:200px;"><?php echo $_POST['report']; ?></textarea>


<form id="rpt" action="">


I have this code that Paolo helped me with last week. This is the start of the jquery code which also has some editor code mixed in with it

$(document).ready(function()
{
  $('.error').hide();
  WYSIWYG.attach('dfarReport', rpt);
  WYSIWYG_Core.addEvent(window, "load", function()
  {
    $('#Save').removeAttr('onclick').click(function()
    {

I tried adding Jonathan's suggested code to this but I get errors when I do this. I also changed "report" to something different just in case but that didn't help either.

IT'S WORKING !!!!!!!!!!!!!!!!!!!!

To get this to work. I added the following:

$(document).ready(function()
{
  $('.error').hide();
  WYSIWYG.attach('dfarReport', dfar);
  WYSIWYG_Core.addEvent(window, "load", function()
  {
    $('#Save').removeAttr('onclick').click(function()
    {
      WYSIWYG.updateTextArea('dfarReport');   <-------------- This is where it needs to go
+2  A: 

EDIT

var report  = $("textarea#report").val();

should be working, however, if you're referencing it by id, then you don't need to use textarea as well

var report  = $("#report").val();

would be equivalent

Also, Are you sure about the name. no typos?

Edit

with OpenWYSIWYG, use WYSIWYG.updateTextArea('report'); before calling the value via javascript

Jonathan Fingland
.val() is correct for textareas as well.
BipedalShark
@nutjob: could you include the html you're using? might just be a typo
Jonathan Fingland
Hi Jonathan, I posted my html above. I also tried your edit but still nothing.. Thanks for helping.
Hey Mr. Paolo... HELP!!!! :)
Paolo, I think you're wrong as of jQuery 1.3. The selector engine now works right to left. So in this case it'd grab all elements with id #report and then filter by textarea.
cdmckay
cdmckay: Interesting. You got a link for that?
Paolo Bergantino
@Paolo, I had heard the same thing as well. The selector engine changed a while back specifically to address the problem you mentioned. I couldn't find a link for it when I checked after your comment. I'm on the dev mailing list for jquery so I might have read it there.
Jonathan Fingland
Yeah I've got a bunch of links opening trying to get to the bottom of it right now. I thought I had heard something similar but earlier today I saw a user here mention that it still behaves this way. I am also trying to track down that question (can't remember for the life of me). I'd really like to know one way or the other.
Paolo Bergantino
Wasn't able to find any links, exactly, but I contacted John Resig (author of jQuery) directly and he said: jQuery evaluates selectors right to left - and it does filter tag#id properly.
Paolo Bergantino
thanks. I saw you asked on twitter but I never saw his response. guess it was by direct message. Good to have an authoritative response on it
Jonathan Fingland
@Paolo: I hadn't read it anywhere, I hear Resig say it in one of his talks :)
cdmckay
@cdmckay: ahhh, that's probably where I heard it as well. His yui theater talk if I remember correctly
Jonathan Fingland
A: 

That syntax should work. Step through the execution with a took like firebug to find out what's causing Javascript to fail. Also, see:

http://stackoverflow.com/questions/144810/jquery-get-textarea-text

karim79
Thanks Karim! I will check it out now. You're right.. something is causing it to fail.
The link is greek to me. It seems that the syntax used in that post is exactly what was offered here. :( I have firebug and I have been looking through it but I don't know how to "step through" the js. Can you please tell me how to do that? Maybe I can see something in there.
A: 

Also, be sure that you have the correct id. Try:

alert($("textarea#report").length);

Also check to make sure you didn't prepend the id with a #. I find what I do sometimes by accident is this:

<textarea id="#report"></textarea>

...instead of...

<textarea id="report"></textarea>
cdmckay
<textarea name="report"></textarea> is another common mistake i see
tschaible
Thanks cdmckay. I looked and it doesn't have the symbol there. I posted the html above.
You didn't specify but I assume that you mean I shouldn't be using name=. I removed it but still nothing.
A: 

I would suggest that you run your whole page through a validator since it looks like your code should work. Also, are you doing it inside of a $(document).ready() function? If not, you might be executing the code before the page is fully loaded.

Dave Markle
A: 

I just tried the following in asp.net MVC 1.0 and it worked fine: var rpt = $("#report").val(); alert(rpt);

The correct way is to use the id as shown above. Though $("textarea#report") will also work but it is slower. $("#report") uses DOM method getElementById and is the fasted way to get an element reference. Please keep in mind the ids are case sensitive.

Hi Momin, for some reason it won't work. I have tried just using the element's id but it wtill won't work. The query string is just blank for the report
Momin, I failed to see the alert on the end of your code. I tried it like you have it and I get [object object]
A: 

try using simple javascript getElementById method and see if that works as following:

alert(document.getElementById("report").value);

if that works that jquery might have a problem and you might need to debug it using the debug version of jquery.