javascript - Adding Comment in textarea and displaying text with Edit and delete buttons -


i have textarea save , cancel buttons updating textarea text in mysql db.

initially mysql db

id  text 1   null 

if enter text in textarea i'm updating mysql db text entered value i'm able achieve requirment once entered text in textarea should update db , text value should display edit , delete buttons.

on clicking edit button should open textarea save , cancel buttons. can aid me out how achieve thanks!

http://jsfiddle.net/a32yjx0k/

html

<div id="b_news"> <form method="post" action="">     </div>     <div class="breaking_news_content">         <div>             <form method="post" action="">             <div>                 <div>                   <textarea id="breaking_news_text" class="breaking_news_text" rows="6" cols="50"  placeholder="add text here..." required></textarea>                 </div>             </div>             <div>                 <input  type="submit" class=" save_breaking_news" value="save changes"/>                 <input type="submit" value="cancel" class=" breaking_news_cancel">             </div>             </form>         </div>     </div> </form> </div> 

jquery

$(function(){     $(".save_breaking_news").click(function(){         var textcontent = $('.breaking_news_text').val();         if(textcontent == '')         {             alert("enter text...");             $('.breaking_news_text').focus();         }         else         {             $.ajax({                 type: "post",                 url: "index.php",                 data:{                     textcontent:textcontent                  },                 success:function(response){                     alert('breaking news updated');                 }             });         }         return false;     }); }); 

php

<?php      if(isset($_post['textcontent']))     {             $breaking_news = mysqli_real_escape_string($con, $_post['textcontent']);             $sql = "update breakingnews set text='".$breaking_news."'";             $result = mysqli_query($con, $sql);      }    ?> 

$(function(){     $(".save_breaking_news").click(function(){         var textcontent = $('.breaking_news_text').text();         if(textcontent == '')         {             alert("enter text...");             $('.breaking_news_text').focus();         }         else         {             $.ajax({                 type: "post",                 url: "index.php",                 data:{                     textcontent:textcontent                  },                 success:function(response){                     alert('breaking news updated');                 }             });         }         return false;     }); }); 

to textbox use (class/id).text();


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -