dcjones
11-22-2003, 06:06 PM
Hi all,
I need a fresh set of eyes to look at the script below. When I run it in the browser I have some icons: Cut, Copy, Paste and so on.
If I click on one of them I get an error:
Line 1
Char 1
Object Expected
Code 0
THIS IS THE CODE
echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"></table>";
echo "<tr>";
echo "<td><form name=\"formc\" method=\"post\" action=\"\">";
echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
echo "<tr>";
echo "<td width=\"29%\"><img src=\"images/translated_text.gif\" width=\"103\" height=\"16\"></td>";
echo "<td width=\"71%\">";
?>
<script language="JavaScript">
//Start JavaScript for button icons
<!-- Hide from non JavaScript browsers
// Display the icons only for MSIE 4.x and higher
if (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.charAt(0) >= 4){
document.write(' <a href="javascript:translatetcut()"><img src="images/cut.gif" alt="Cut all" border="0"></a>\n');
document.write(' <a href="javascript:translatecopy()"><img src="images/copy.gif" alt="Copy all" border="0"></a>\n');
document.write(' <a href="javascript:translatepaste()"><img src="images/paste.gif" alt="Paste all" border="0"></a>\n');
}
// Display the icons for other JavaScript aware browsers
document.write(' <a href="javascript:translatedelete()"><img src="images/delete.gif" alt="Delete all" border="0"></a>\n');
document.write(' <a href="javascript:translatemail()"><img src="images/mail.gif" alt="E-mail" border="0"></a>\n');
document.write(' <a href="javascript:translatesearch()"><img src="images/search.gif" alt="Search the Web" border="0"></a>\n');
document.write('<br>\n');
//-->
//End JavaScript for button icons
</script>
<?
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan=\"2\"><textarea name=\"results\" cols=\"80\" rows=\"10\" id=\"formc\">{$chunk}</textarea></td>";
echo "</tr>";
echo "</table>";
echo "</form></td>";
echo " </tr>";
echo "</table>";
?>
<script language="JavaScript">
//Start of JavaScript for Original Text
<!-- Hide from non JavaScript browsers
// Functions for various editing
// Copy the text
function translatecopy(){
// Copy the text into memory
document.formc.result.createTextRange().execCommand("Copy");
// Focus on the text
document.formc.results.focus();
}
// Paste the text
function translatepaste(){
// Paste the text from memory
document.formc.results.createTextRange().execCommand("Paste");
// Focus on the text
document.formc.results.focus();
}
// Cut the text
function translatecut(){
// First copy the text
document.formc.results.createTextRange().execCommand("Copy");
// Then delete it
document.formc.results.value="";
// Focus on the text
document.formc.results.focus();
}
// Delete the text
function translatedelete(){
// Define the text as empty string
document.formc.source.value="";
// Focus on the text
document.formc.source.focus();
}
// Convert the text into appropriate form
function text_escape(text){
new_text='';
// Simple browser detection
if(navigator.appName == "Microsoft Internet Explorer") msie=1;
else msie=0;
// Escape only some characters
for(i=0; text.charAt(i) ; i++){
character=escape(text.charAt(i));
//prompt(character);
// Is this MSIE ?
if(msie){
// uuencode twice for MSIE if needed
if(text.charCodeAt(i)<48 || character=='%3F'){
new_text=new_text+escape(character);
// If not...
}else new_text=new_text+text.charAt(i);
// If not... (Netscape?)
}else{
// Do we need to escape it?
if(text.charCodeAt(i)>127 || character=='%0D' || character=='%0A' || character=='%23' || character=='%26' || character=='%3F'){
new_text=new_text+character;
// If not...
}else new_text=new_text+text.charAt(i);
}
}
return new_text;
}
// Mail the text
function translatemail(){
who=prompt("E-mail address to send the text: ","");
if(!who) return;
what=prompt("The subject: ","Academy-life translation result ");
if(!what) return;
text=document.formc.results.value;
mejl='mailto:' +text_escape(who)+ '?subject=' +text_escape(what)+ '&body=' +text_escape(text);
parent.location.href=mejl;
}
// Search the web for the text
function translatesearch(){
text=document.formc.results.value;
text=escape(text);
to=document.formc.to.value;
url=''+text;
parent.location.href=url;
}
//-->
//End JavaScript for Original Text
</script>
Please can some one have a look to see if I have missed some thing.
Kind Regards
Dereck
I need a fresh set of eyes to look at the script below. When I run it in the browser I have some icons: Cut, Copy, Paste and so on.
If I click on one of them I get an error:
Line 1
Char 1
Object Expected
Code 0
THIS IS THE CODE
echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"></table>";
echo "<tr>";
echo "<td><form name=\"formc\" method=\"post\" action=\"\">";
echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
echo "<tr>";
echo "<td width=\"29%\"><img src=\"images/translated_text.gif\" width=\"103\" height=\"16\"></td>";
echo "<td width=\"71%\">";
?>
<script language="JavaScript">
//Start JavaScript for button icons
<!-- Hide from non JavaScript browsers
// Display the icons only for MSIE 4.x and higher
if (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.charAt(0) >= 4){
document.write(' <a href="javascript:translatetcut()"><img src="images/cut.gif" alt="Cut all" border="0"></a>\n');
document.write(' <a href="javascript:translatecopy()"><img src="images/copy.gif" alt="Copy all" border="0"></a>\n');
document.write(' <a href="javascript:translatepaste()"><img src="images/paste.gif" alt="Paste all" border="0"></a>\n');
}
// Display the icons for other JavaScript aware browsers
document.write(' <a href="javascript:translatedelete()"><img src="images/delete.gif" alt="Delete all" border="0"></a>\n');
document.write(' <a href="javascript:translatemail()"><img src="images/mail.gif" alt="E-mail" border="0"></a>\n');
document.write(' <a href="javascript:translatesearch()"><img src="images/search.gif" alt="Search the Web" border="0"></a>\n');
document.write('<br>\n');
//-->
//End JavaScript for button icons
</script>
<?
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan=\"2\"><textarea name=\"results\" cols=\"80\" rows=\"10\" id=\"formc\">{$chunk}</textarea></td>";
echo "</tr>";
echo "</table>";
echo "</form></td>";
echo " </tr>";
echo "</table>";
?>
<script language="JavaScript">
//Start of JavaScript for Original Text
<!-- Hide from non JavaScript browsers
// Functions for various editing
// Copy the text
function translatecopy(){
// Copy the text into memory
document.formc.result.createTextRange().execCommand("Copy");
// Focus on the text
document.formc.results.focus();
}
// Paste the text
function translatepaste(){
// Paste the text from memory
document.formc.results.createTextRange().execCommand("Paste");
// Focus on the text
document.formc.results.focus();
}
// Cut the text
function translatecut(){
// First copy the text
document.formc.results.createTextRange().execCommand("Copy");
// Then delete it
document.formc.results.value="";
// Focus on the text
document.formc.results.focus();
}
// Delete the text
function translatedelete(){
// Define the text as empty string
document.formc.source.value="";
// Focus on the text
document.formc.source.focus();
}
// Convert the text into appropriate form
function text_escape(text){
new_text='';
// Simple browser detection
if(navigator.appName == "Microsoft Internet Explorer") msie=1;
else msie=0;
// Escape only some characters
for(i=0; text.charAt(i) ; i++){
character=escape(text.charAt(i));
//prompt(character);
// Is this MSIE ?
if(msie){
// uuencode twice for MSIE if needed
if(text.charCodeAt(i)<48 || character=='%3F'){
new_text=new_text+escape(character);
// If not...
}else new_text=new_text+text.charAt(i);
// If not... (Netscape?)
}else{
// Do we need to escape it?
if(text.charCodeAt(i)>127 || character=='%0D' || character=='%0A' || character=='%23' || character=='%26' || character=='%3F'){
new_text=new_text+character;
// If not...
}else new_text=new_text+text.charAt(i);
}
}
return new_text;
}
// Mail the text
function translatemail(){
who=prompt("E-mail address to send the text: ","");
if(!who) return;
what=prompt("The subject: ","Academy-life translation result ");
if(!what) return;
text=document.formc.results.value;
mejl='mailto:' +text_escape(who)+ '?subject=' +text_escape(what)+ '&body=' +text_escape(text);
parent.location.href=mejl;
}
// Search the web for the text
function translatesearch(){
text=document.formc.results.value;
text=escape(text);
to=document.formc.to.value;
url=''+text;
parent.location.href=url;
}
//-->
//End JavaScript for Original Text
</script>
Please can some one have a look to see if I have missed some thing.
Kind Regards
Dereck