Hi,
Im using the following code to edit an xml file on my server:
<html>
<head>
<script type="text/javascript">
function insertString(el,str){
// Mozilla XUL extensions to the DOM
if(typeof el.selectionStart=='number')
el.value=el.value.slice(0,el.selectionStart)+str+el.value.slice(el.selectionEnd,el.value.length);
// IE
else if(document.selection){
el.focus();
document.selection.createRange().text=str;
}
// no support
else el.value+=str
}
</script>
</head>
<body>
<?php
$XMLfile = "content.xml";
if(isset($_POST['submit'])){ // Saving data
$fh = fopen($XMLfile,"w");
fwrite($fh,stripslashes($_POST['fileContent']));
fclose($fh);
echo "Data saved in $XMLfile";
}
else{ // Show form
$fh = fopen($XMLfile,"r");
$data = fread($fh,filesize($XMLfile));
fclose($fh);
?>
<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post">
<textarea id="fileContent" name="fileContent" cols="50" rows="30"><? echo $data; ?></textarea>
<input type="button" value="Bolden Text" onclick="insertString(document.getElementById('fileContent'),'<b> </b>')">
<input type="submit" name="submit" value="Save" onClick="return confirm('Click OK to save the data')">
</form>
<?
}
?>
</body>
</html>
in this section of code:
<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post">
<textarea id="fileContent" name="fileContent" cols="50" rows="30"><? echo $data; ?></textarea>
<input type="button" value="Bolden Text" onclick="insertString(document.getElementById('fileContent'),'<b> </b>')">
<input type="submit" name="submit" value="Save" onClick="return confirm('Click OK to save the data')">
</form>
I im using javascript to insert the <b> </b> tags to the text area. my problem is that when i clcik the button these tags appear as the <b> </b> which doesnt work for me. i need them in the escape character format.
any ideas how i might resolve this?
thanks