How to get value of a text box in a dialog box using jquery in php. I am opening a dialog box on click of button in which there is a text box as comments. I want this value to submit to the database. But the value i get is undefined or blank when i alert it. I am unable to get the message value of the textbox. My Code is as:
<script type="text/javascript" language="javascript"> $(document).ready(function(){ $(".QTPopup").css('display','none'); $(".lnchPopop").click(function(){ $(".QTPopup").animate({width: 'show'}, 'slow');}); $(".closeBtn").click(function(){ $(".QTPopup").css('display', 'none'); }); $(document).on('click','.submit_comment',function(){ alert("Hello"); var comments=$('#comment_by_user').val(); alert(comments); var comments1= document.getElementById("comment_by_user").value; alert(comments1); }); }); </script> The Dialog box opens on the click of the Comment Hyperlink.
a href="#" class="lnchPopop">Comments</a> <div class="QTPopup" style="display: none"> <div class="QTPopupCntnr"> <div class="gpBdrLeftTop"></div> <div class="gpBdrRightTop"></div> <div class="gpBdrTop"></div> <div class="gpBdrLeft"> <div class="gpBdrRight"> <div class="caption"> Send Your Messages </div> <a href="#" class="closeBtn" title="Close"></a> <div class="content"> <br /> <table> <tr> <td style="height:5px;"></td> </tr> <tr> <td> </td> </tr> <tr> <td> <textarea class="textareagradiant" id="comment_by_user" name="comment_by_user" style="width:428px; height:116px; border:1px solid #CFCECE;"> </textarea> </td> </tr> <tr> <td style="height:5px;"></td> </tr> <tr> <td style="height:10px;"></td> </tr> <tr> <td> <input type="button" value="Submit" class="gbtn_s submit_comment" /> <input type="button" value="Reset" class="gbtn_s" /> </td> </tr> </table> </div> </div> </div> <div class="gpBdrLeftBottom"></div> <div class="gpBdrRightBottom"></div> <div class="gpBdrBottom"></div </div> </div>