Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.