Solarpitch Posted May 15, 2011 Share Posted May 15, 2011 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; }); }); Quote Link to comment https://forums.phpfreaks.com/topic/236462-getting-the-value-of-a-textarea-using-a-lightbox/ Share on other sites More sharing options...
Zane Posted May 15, 2011 Share Posted May 15, 2011 try using $('#freetext').text() or $('#freetext').html(), because textarea is a tag with no value... only innerHTML or innerText if you will. Quote Link to comment https://forums.phpfreaks.com/topic/236462-getting-the-value-of-a-textarea-using-a-lightbox/#findComment-1215686 Share on other sites More sharing options...
Solarpitch Posted May 15, 2011 Author Share Posted May 15, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/236462-getting-the-value-of-a-textarea-using-a-lightbox/#findComment-1215696 Share on other sites More sharing options...
Zane Posted May 15, 2011 Share Posted May 15, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/236462-getting-the-value-of-a-textarea-using-a-lightbox/#findComment-1215697 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.