rain13 Posted April 2, 2011 Share Posted April 2, 2011 fist thing I can think of is passing contents to editor from php by using str_replace() with <textarea id="Editor" style="height:300px; width:600px"></textarea> but then I found that since I have ' and "" in my contents which means that if I add value="something" then " would break it.Next thing I thought about was to convert it into hex code but then I found that when I set it's value, i cant have func call in value="" which means I wont be able to put hex string back to normal string. any other ideas?Edit: I found that I can set value by seeting text between <textarea> tags, but problem is that if comment contains </textarea>, then it cuts anything after that. <html><head><title>PHP using AJAX</title><script type="text/javascript">var time_variable;function getXMLObject() //XML OBJECT{ var xmlHttp = false; try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP") // For Old Microsoft Browsers } catch (e) { try { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP") // For Microsoft IE 6.0+ } catch (e2) { xmlHttp = false // No Browser accepts the XMLHTTP Object then false } } if (!xmlHttp && typeof XMLHttpRequest != 'undefined') { xmlHttp = new XMLHttpRequest(); //For Mozilla, Opera Browsers } return xmlHttp; // Mandatory Statement returning the ajax object created}var xmlhttp = new getXMLObject(); //xmlhttp holds the ajax objectfunction ajaxFunction() { var getdate = new Date(); //Used to prevent caching during ajax call if(xmlhttp) { var txtname = document.getElementById("Editor"); xmlhttp.open("POST","post.php",true); //calling testing.php using POST method xmlhttp.onreadystatechange = handleServerResponse; xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xmlhttp.send("Editor=" + txtname.value); //Posting txtname to PHP File }}function handleServerResponse() { if (xmlhttp.readyState == 4) { if(xmlhttp.status == 200) { document.getElementById("message").innerHTML=xmlhttp.responseText; //Update the HTML Form element } else { alert("Error during AJAX call. Please try again"); } }}function set(style) { var StyleStart = "["+style+"]"; var StyleEnd = "[/"+style+"]"; if (style == "youtube") { var StyleStart = "[video host=youtube.com]"; var StyleEnd = "[/video]"; } if (style == "google") { var StyleStart = "[video host=google.com]"; var StyleEnd = "[/video]"; } var ta = document.getElementById("Editor"); if (document.selection) { str = document.selection.createRange().text document.selection.createRange().text = StyleStart + str + StyleEnd; return true; } else if (ta.selectionStart) { var startPos = ta.selectionStart; var endPos = ta.selectionEnd; var str = ta.value.substring(startPos, endPos); ta.value = ta.value.substring(0, startPos) + StyleStart + str + StyleEnd + ta.value.substring(endPos, ta.value.length); return true; } else { return false; }}</script><div id="message" name="message"></div><br><input type="button" value="bold" onclick="set('b')" /> <input type="button" value="Italic" onclick="set('i')" /> <input type="button" value="Underline" onclick="set('u')" /> <input type="button" value="Image" onclick="set('img')" /> <input type="button" value="Link" onclick="set('lnk')" /> <input type="button" value="Quote" onclick="set('quote')" /> <input type="button" value="Youtube" onclick="set('youtube')" /> <input type="button" value="Google video" onclick="set('google')" /><br /><textarea id="Editor" style="height:300px; width:600px"></textarea><br><input type="button" value="Preview" onclick="ajaxFunction()" /><input type="submit" value="Submit" /> Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.