i have textarea 2 buttons. 1 button preview text entered, , other 1 submits text server. here code:
<?php session_start(); $_session['shortdescription']=''; if(isset($_post['submit'])) {...} ?> <form name="news" action="add_news.php" method="post"> <textarea rows="5" name="shortdescription" id="shortdescription"></textarea>  <input type="button" name="preview" value="preview description"> <input type="submit" name="submit" value="submit"> </form>
i beginner in php , javascript. know problem can solve using ajax. new ajax. can me please?
from understand, you're initiating session , afterwards, want create $_session variable based on types in text area. assuming don't want page change when user clicks preview (but want able use $_session variable in future situations) you'll need use ajax (as mentioned). easiest way i've found accomplish use jquery , ajax together.
basically, you'll create javascript function (using jquery) select whenever preview button clicked. this. first add id within input tag...
<input type="button" id="previewid" name="preview" value="preview description">
next create function in javascript file...
$('#previewid').click(function() { request = $.ajax({ url: "/form.php", type: "post", data: serializeddata }); });
form.php form checks see if $_post['shortdescription'] exists, if does, sanitize , store in $_session['shortdescription']. "serializeddata" contents of text area being passed. (which passing variable contents on url. example, if shortdescription = "hellothere", serialized data "shortdescription=hellothere
", appends url like...
"www.website.com/form.php?shortdescription=hellothere
"
keep in mind not typically manually set though, show concept. use like:
var serializeddata = $form.serialize();
view question example ajax request.
disclaimer: there may better way accomplish this, figured offer 1 possibility since no 1 had answered yet!
Comments
Post a Comment