Jump to content

Getting the value of a Textarea using a lightbox


Solarpitch

Recommended Posts

Hey Guys,

 

I'm trying to get the value of a textarea after a click event is fired. I'm able to achieve this with the code below when I don't display the textarea in a lightbox.

 

Basically, I have a link that triggers a lightbox which displays the textarea. When someone enters something into the textarea and clicks insert, I'm trying to get the value via a jquery function and alert it.

 

 

LIGHTBOX

<a href="#free_text" rel="facebox">Add Text (Display lightbox with textarea)</a>

// Lightbox with textarea
   <div id="free_text" style="display:none;">
  
<TEXTAREA NAME="freetext" id="freetext" class="freetext"></TEXTAREA><br/>
<INPUT TYPE=SUBMIT VALUE="Insert"  class="insert" id="<?php echo $row->id; ?>">

  </div>

 

 

When I click insert above the value does not get passed to the function below. But works fine when not using the lightbox.

 

JQUERY


$(function() {
$(".insert").live('click', function() {

	var description = $("#freetext").val();
	alert(description);

	$.facebox.close(); 
	return false;
});
});

 

 

Thanks for your reply but with both of them it still doesnt return a value. I'm just thinking, does it have anything to do with the fact the div that contains the textarea is set as display:none; initially in the css and it's unable to get the value or html of it because of this?

you've binded click to the live() function, I don't see why it should be a problem.  You really only need the live function for dynamic input's.. i.e. inputs that weren't originally in the HTML.  display:none only means it's not displayed, but it still appears in the source code.  If you use a function like append of prepend or something to place another input on the page.. then you would use live() to access that input's click function.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.