Javascript variable question

TechBoyJK

Lifer
Oct 17, 2002
16,699
60
91
Ok, I'm not sure what I'm doing wrong here. I'm using the jQuery dialog UI module, and that works fine. I'm writing a script so that when someone hits 'save' on the modal popup box, it will close, and then do some work.

Basically, when someone clicks save, I want to capture what's they've written in the text box, and send that text to a remote function.



Code:
"Save": function() {
     $( this ).dialog( "close" );
 
     var caption = $("input##imageCaption").val();
    
     $.getJSON("http://mydomain.com/config/cfc/images.cfc?method=updateImageCaption&imageID=12345&caption=" + caption,function(result){});					
},

I'm just trying to declare a variable of 'caption', and set that variable to contain the contents of the textarea (id="imageCaption). This way, when I do the getJson request to update the comment, I can just append the 'caption' variable to the part of the string that defines the argument.

<textarea name="imageCaption" cols="55" rows="10" id="imageCaption"></textarea>

However, as of now, caption is being appended to the string as 'undefined'. Ideas?
 

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,469
4,321
75
120px-Hash_%284106225932%29.jpg
120px-Hash_%284106225932%29.jpg


Too many "hashes"? :D

IDs on your page should be unique, so you should be able to refer to this thing with just $('#imageCaption')

Personally, I'd avoid JQuery:
Code:
var caption = document.getElementById('imageCaption').value;
But that's probably just me these days. :(
 

TechBoyJK

Lifer
Oct 17, 2002
16,699
60
91
120px-Hash_%284106225932%29.jpg
120px-Hash_%284106225932%29.jpg


Too many "hashes"? :D

IDs on your page should be unique, so you should be able to refer to this thing with just $('#imageCaption')

Personally, I'd avoid JQuery:
Code:
var caption = document.getElementById('imageCaption').value;
But that's probably just me these days. :(

Oh, duh, should have noted.

Those are instances where a coldfusion var is output. #cfmlVar#

Going to try your code now, thanks.