seems to work fine if I add
Code:
document.getElementById('bld').addEventListener('click',iBold,false);
through the console. Could that mean the elements haven't loaded yet?
As for the dollar function, I added it as a means of shortening the code. Seemed redundant to keep typing out document.getElementById() when I could simplify it.
Updated code:
Javascript
:
Code:
if (window.addEventListener){window.addEventListener('load',iFrameOn,false);}
else if (document.addEventListener) {
document.addEventListener('load',iFrameOn,false);
$('bld').addEventListener('click',iBold,false);
$('undrline').addEventListener('click',iUnderline,false);
$('italic').addEventListener('click',iItalic,false);
$('fontColor').addEventListener('click',iForeColor,false);
$('unlist').addEventListener('click',iUnorderedList,false);
$('orlist').addEventListener('click',iOrderedList,false);
$('imge').addEventListener('click',iImage,false);
$('deny').addEventListener('click',denyFR,false);
$('accept').addEventListener('click',acceptFR,false);
$('sbmt').addEventListener('click',sendData,false);
}
else if (document.attachEvent){document.attachEvent('onload',iFrameOn);}
else if (window.attachEvent){window.attachEvent('onload',iFrameOn);}
function $(element){return document.getElementById(element);}
function iFrameOn(){richTextField.document.designMode = 'On';}
function iBold(){richTextField.document.execCommand('bold',false,null);}
function iUnderline(){richTextField.document.execCommand('underline',false,null);}
function iItalic(){richTextField.document.execCommand('italic',false,null);}
function iForeColor() {
var color = prompt('Enter a color', '');
richTextField.document.execCommand('ForeColor',false,color);
}
function iUnorderedList() {
richTextField.document.execCommand('InsertUnorderedList',false,'newUL');
}
function iOrderedList() {
richTextField.document.execCommand('InsertOrderedList',false,'newOL');
}
function iImage() {
var imgSrc = prompt('Enter image location', '');
if (imgSrc != null) {
richTextField.document.execCommand('insertimage',false,imgSrc);
}
}
function denyFR() {
var dfrHR = new XMLHttpRequest();
var frURL = "fRequest.php";
var denyRequest = 2;
var statusOfRequest = "frStatus="+denyRequest;
dfrHR.open("POST", frURL, true);
dfrHR.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
dfrHR.onreadystatechange = function() {
if (dfrHR.readyState == 4 && dfrHR.status == 200) {
$('fStatus').innerHTML = "Friend request denied";
}
}
dfrHR.send(statusOfRequest);
}
function acceptFR() {
var afrHR = new XMLHttpRequest();
var URL = "fRequest.php";
var acceptRequest = 1;
var aRequestStatus = "frStatus="+acceptRequest;
afrHR.open("POST", URL, true);
afrHR.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
afrHR.onreadystatechange = function() {
if (afrHR.readyState == 4 && afrHR.status == 200) {
$('fStatus').innerHTML = "Friend request accepted";
}
}
afrHR.send(aRequestStatus);
}
function sendData() {
var hr = new XMLHttpRequest();
var url = "rtf.php";
var usrname = $('author').value;
var txtField = window.frames['richTextField'].document.body.innerHTML;
var vars = "author="+usrname+"&post="+txtField;
hr.open("POST", url, true);
hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
hr.onreadystatechange = function() {
if (hr.readyState == 4 && hr.status == 200) {
var return_data = hr.responseText;
$('status').innerHTML = return_data;
}
}
hr.send(vars);
$('status').innerHTML = "Posting...";
}
HTML:
Code:
<iframe name="richTextField" id="richTextField"></iframe>
<br />
<div id="wysiwyg_bottom">
<a id="bld" class="button" href="#">B</a>
<a id="undrline" class="button" href="#">U</a>
<a id="italic" class="button" href="#">I</a>
<a id="fontColor" class="button" href="#">Color</a>
<a id="unlist" class="button" href="#">UL</a>
<a id="orlist" class="button" href="#">OL</a>
<a id="imge" class="button" href="#">Image</a>
<input id="sbmt" class="submit_button" type="button" name="submit" value="Post" />
</div>
<p id="status"></p>
</form>