473,769 Members | 1,882 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Script error

2 New Member
Hi everybody,

First of all I'm not a java hero but I tried to write my own text editor.
Everything works but only when the existing text need to be re-edited the butttons of my editor seem not to work anymore...

This is the main script :

Expand|Select|Wrap|Line Numbers
  1. <!--
  2.   function storeCaret (txtarea) { 
  3.     if (txtarea.createTextRange) { 
  4.       selectedRange = document.selection.createRange().duplicate();
  5.       selectedInputArea = txtarea;
  6.     } 
  7.   } 
  8.  
  9.   function WrapIE(txtarea, lft, rgt) {
  10.     strSelection = document.selection.createRange().text;
  11.     if (strSelection!='') {
  12.       document.selection.createRange().text = lft + strSelection + rgt;
  13.       var range = document.selection.createRange();
  14.       range.collapse(true);
  15.       range.moveStart('character', lft.length+strSelection.length+rgt.length);
  16.       range.select();
  17.       storeCaret(txtarea)
  18.     }
  19.     txtarea.focus();
  20.   }
  21.  
  22.   function wrapMoz(txtarea, lft, rgt) {
  23.     var selLength = txtarea.textLength;
  24.     var selStart = txtarea.selectionStart;
  25.     var selEnd = txtarea.selectionEnd;
  26.     if (selEnd==1 || selEnd==2) selEnd=selLength;
  27.     var s1 = (txtarea.value).substring(0,selStart);
  28.     var s2 = (txtarea.value).substring(selStart, selEnd)
  29.     var s3 = (txtarea.value).substring(selEnd, selLength);
  30.     txtarea.value = s1 + lft + s2 + rgt + s3;
  31.     txtarea.focus();
  32.     var cPos=s1.length+(lft.length+s2.length+rgt.length);
  33.     txtarea.setSelectionRange(cPos,cPos);
  34.   }
  35.  
  36.   function wrapTag(txtarea, lft, rgt) {
  37.       lft = unescape(lft);
  38.       rgt = unescape(rgt);
  39.     if (document.all) {
  40.       WrapIE(txtarea, lft, rgt);
  41.     }
  42.     else if (document.getElementById) {
  43.       wrapMoz(txtarea, lft, rgt);
  44.     }
  45.   }
  46.  
  47.   function wrapWithLink(txtarea) {
  48.     var my_link = prompt('URL:','http://');
  49.     if (my_link != null) {
  50.       lft='<a href="' + my_link + '">';
  51.       rgt='</a>';
  52.       wrapTag(txtarea, lft, rgt);
  53.     }
  54.     return;
  55.   }
  56.  
  57.   function insertIE (txtarea, text) {
  58.     if (txtarea.createTextRange && selectedRange) { 
  59.       var caretPos = selectedRange; 
  60.       caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text+caretPos.text + ' ' : text+caretPos.text;
  61.     } else {
  62.       txtarea.value = txtarea.value + text; 
  63.     }
  64.     txtarea.focus();
  65.     return;
  66.   }
  67.  
  68.  
  69.  
  70.   function insertMoz(txtarea , lft) {
  71.     var rgt='';
  72.     wrapTag(txtarea, lft, rgt);
  73.     return;
  74.   }
  75.  
  76.   function insertTag(txtarea , lft) {
  77.     if (document.all) {
  78.       insertIE(txtarea, lft);
  79.     }
  80.     else if (document.getElementById) {
  81.       insertMoz(txtarea, lft);
  82.     }
  83.   }
  84.  
  85.   function insertImage(txtarea) {
  86.     var my_link = prompt('IMG URL:','http://');
  87.     if (my_link != null) {
  88.       lft='<img src="' + my_link + '" />';
  89.       insertTag(txtarea, lft);
  90.     }
  91.     return;
  92.   }
  93. function mouseover(el) {
  94.   el.className = 'raise';
  95. }
  96.  
  97. function mouseout(el) {
  98.   el.className = 'teksteditorImg';
  99. }
  100.  
  101. function mousedown(el) {
  102.   el.className = 'teksteditorImgPress';
  103. }
  104.  
  105. function mouseup(el) {
  106.   el.className = 'raise';
  107. }
  108.  
  109.  
  110. //-->
  111.  

This is the editor that works :
[HTML]<table width="100%" border="0" cellpadding="0" cellspacing="0" class="ContentT able_Content_Su bTable">
<tr>
<td><form action="nieuwsM anagement_inhou d.php" method="post" enctype="multip art/form-data" name="form1">
<p>
Tekst :<br>
<img src="../images/bttns/teksteditor/bttn_bold_01.gi f" alt="Vet" width="18" height="18" class="tekstedi torImg" title="Highligh t some text and click for bold" onclick="wrapTa g(this.parentNo de.parentNode.e lements['txt'], '<b>', '</b>');" onmousedown="mo usedown(this);" onmouseup="mous eup(this);" onmouseover="mo useover(this);" onmouseout="mou seout(this);">
<img src="../images/bttns/teksteditor/bttn_italic_01. gif" width="18" height="18" title="Highligh t some text and click for italic" class="tekstedi torImg" onmouseover="mo useover(this);" onmouseout="mou seout(this);" onmousedown="mo usedown(this);" onmouseup="mous eup(this);" onclick="wrapTa g(this.parentNo de.parentNode.e lements['txt'], '<i>', '</i>')">
<img src="../images/bttns/teksteditor/bttn_underlined _01.gif" width="18" height="18" title="Highligh t some text and click for underlined" class="tekstedi torImg" onmouseover="mo useover(this);" onmouseout="mou seout(this);" onmousedown="mo usedown(this);" onmouseup="mous eup(this);" onclick="wrapTa g(this.parentNo de.parentNode.e lements['txt'], '<u>', '</u>')">
<img src="../images/bttns/teksteditor/bttn_alignCente r_01.gif" width="18" height="18" title="Highligh t some text and click to center" class="tekstedi torImg" onmouseover="mo useover(this);" onmouseout="mou seout(this);" onmousedown="mo usedown(this);" onmouseup="mous eup(this);" onclick="wrapTa g(this.parentNo de.parentNode.e lements['txt'], '<div align=%22center %22>', '</div>')">
<img src="../images/bttns/teksteditor/bttn_alignRight _01.gif" width="18" height="18" title="Highligh t some text and click to right align" class="tekstedi torImg" onmouseover="mo useover(this);" onmouseout="mou seout(this);" onmousedown="mo usedown(this);" onmouseup="mous eup(this);" onclick="wrapTa g(this.parentNo de.parentNode.e lements['txt'], '<div align=%22right% 22>', '</div>')">
<img src="../images/bttns/teksteditor/bttn_blockQuote _01.gif" width="18" height="18" title="Highligh t some text and click for a blockquote" class="tekstedi torImg" onmouseover="mo useover(this);" onmouseout="mou seout(this);" onmousedown="mo usedown(this);" onmouseup="mous eup(this);" onclick="wrapTa g(this.parentNo de.parentNode.e lements['txt'], '<blockquote>' , '</blockquote>')">
<img src="../images/bttns/teksteditor/bttn_list_01.gi f" width="18" height="18" title="Highligh t some text and click for a bulleted list" class="tekstedi torImg" onmouseover="mo useover(this);" onmouseout="mou seout(this);" onmousedown="mo usedown(this);" onmouseup="mous eup(this);" onclick="wrapTa g(this.parentNo de.parentNode.e lements['txt'], '<li>', '</li>')">
<img src="../images/bttns/teksteditor/bttn_horizRule_ 01.gif" width="18" height="18" title="Insert a horizontal rule" class="tekstedi torImg" onmouseover="mo useover(this);" onmouseout="mou seout(this);" onmousedown="mo usedown(this);" onmouseup="mous eup(this);" onclick="insert Tag(this.parent Node.parentNode .elements['txt'],'<hr />');">
<img src="../images/bttns/teksteditor/bttn_link_01.gi f" width="18" height="18" title="Highligh t some text and click to add a link" class="tekstedi torImg" onmouseover="mo useover(this);" onmouseout="mou seout(this);" onmousedown="mo usedown(this);" onmouseup="mous eup(this);" onclick="wrapWi thLink(this.par entNode.parentN ode.elements['txt']);">

<textarea wrap="soft" name="txt" cols="85" rows="10" class="formfiel d" id="txt" onSelect="store Caret(this);" onClick="storeC aret(this);" onKeyUp="storeC aret(this);"></textarea>
</p>
<p align="center">
<input name="new" type="hidden" value="active"> <input name="m" type="hidden" value="<?php echo $m?>"><input name="s" type="hidden" value="<?php echo $s?>"><input name="imageFiel d" type="image" src="../images/bttns/bttn_OK_70x20_0 1.jpg" width="70" height="20" border="0">
</p>
</form></td>
</tr>
</table>
[/HTML]

The Error part follows in the next window...
Oct 4 '05 #1
2 2464
fnsbe
2 New Member
Now... The user sends this text into a database. When he wants to edit the existing text he clicks a button and a layer, that was hidden, appears. The layer shows the same kind of editor with the existing text in it.
Everything works... but my java buttons don't...

This is the layer with the editor that doesn't work properly :
Expand|Select|Wrap|Line Numbers
  1. <div id="edittekst<?php echo $paragr['artikel_id']?>" style="position:absolute; width:400px; height:100px; z-index:4; visibility: hidden; left:300px;" class="layer">
  2.   <table width="400" border="0" cellspacing="0" cellpadding="0">
  3.     <tr>
  4.       <td width="394" class="layer_TableHeader">Wijzig de tekst </td>
  5.       <td class="layer_TableHeader" style="margin-left:0px;"><div align="center"><a href="#"><img src="../images/bttns/bttn_closeLayer_01.jpg" alt="Sluiten" width="30" height="30" border="0" onClick="MM_showHideLayers('edittekst<?php echo $paragr['artikel_id']?>','','hide')"></a></div></td>
  6.     </tr>
  7.     <tr>
  8.       <td colspan="2" class="layer_TableContent"><form action="nieuwsManagement_inhoud.php" method="post" enctype="multipart/form-data" name="form<?php echo $submenus['submenu_id']?>b">
  9.         &nbsp;<br>
  10.         <table width="380" border="0" cellpadding="0" cellspacing="0" class="ContentTable_Content_SubTable">
  11.           <tr>
  12.             <td>Wijzig Titel</td>
  13.             <td>: 
  14.             <input name="titel" type="text" class="formfield" value="<?php echo $paragr['titel']?>" size="40" maxlength="60"></td>
  15.           </tr>
  16.           <tr>
  17.             <td colspan="2">Wijzig de tekst :<br>
  18.              <img src="../images/bttns/teksteditor/bttn_bold_01.gif" alt="Vet" width="18" height="18" class="teksteditorImg" title="Highlight some text and click for bold"  onmousedown="mousedown(this);" onmouseup="mouseup(this);"  onmouseover="mouseover(this);" onmouseout="mouseout(this);"  onclick="wrapTag(this.parentNode.parentNode.elements['txtnew'], '<b>', '</b>');">
  19.              <img src="../images/bttns/teksteditor/bttn_italic_01.gif" width="18" height="18"  title="Highlight some text and click for italic" class="teksteditorImg"  onmouseover="mouseover(this);" onmouseout="mouseout(this);"  onmousedown="mousedown(this);" onmouseup="mouseup(this);"  onclick="wrapTag(this.parentNode.parentNode.elements['txtnew'], '<i>', '</i>')">
  20.              <img src="../images/bttns/teksteditor/bttn_underlined_01.gif" width="18" height="18"  title="Highlight some text and click for underlined" class="teksteditorImg"  onmouseover="mouseover(this);" onmouseout="mouseout(this);"  onmousedown="mousedown(this);" onmouseup="mouseup(this);"  onclick="wrapTag(this.parentNode.parentNode.elements['txtnew'], '<u>', '</u>')">
  21.              <img src="../images/bttns/teksteditor/bttn_alignCenter_01.gif" width="18" height="18"  title="Highlight some text and click to center" class="teksteditorImg"  onmouseover="mouseover(this);" onmouseout="mouseout(this);"  onmousedown="mousedown(this);" onmouseup="mouseup(this);"  onclick="wrapTag(this.parentNode.parentNode.elements['txtnew'], '<div align=%22center%22>', '</div>')">
  22.              <img src="../images/bttns/teksteditor/bttn_alignRight_01.gif" width="18" height="18"  title="Highlight some text and click to right align" class="teksteditorImg"  onmouseover="mouseover(this);" onmouseout="mouseout(this);"  onmousedown="mousedown(this);" onmouseup="mouseup(this);"  onclick="wrapTag(this.parentNode.parentNode.elements['txtnew'], '<div align=%22right%22>', '</div>')">
  23.              <img src="../images/bttns/teksteditor/bttn_blockQuote_01.gif" width="18" height="18"  title="Highlight some text and click for a blockquote" class="teksteditorImg"  onmouseover="mouseover(this);" onmouseout="mouseout(this);"  onmousedown="mousedown(this);" onmouseup="mouseup(this);"  onclick="wrapTag(this.parentNode.parentNode.elements['txtnew'], '<blockquote>', '</blockquote>')">
  24.              <img src="../images/bttns/teksteditor/bttn_list_01.gif" width="18" height="18"  title="Highlight some text and click for a bulleted list"  class="teksteditorImg" onmouseover="mouseover(this);"  onmouseout="mouseout(this);" onmousedown="mousedown(this);"  onmouseup="mouseup(this);"  onclick="wrapTag(this.parentNode.parentNode.elements['txtnew'], '<li>', '</li>')">
  25.              <img src="../images/bttns/teksteditor/bttn_horizRule_01.gif" width="18" height="18"  title="Insert a horizontal rule" class="teksteditorImg"  onmouseover="mouseover(this);" onmouseout="mouseout(this);"  onmousedown="mousedown(this);" onmouseup="mouseup(this);"  onclick="insertTag(this.parentNode.parentNode.elements['txtnew'],'<hr />');">
  26.              <img src="../images/bttns/teksteditor/bttn_link_01.gif" width="18" height="18"  title="Highlight some text and click to add a link" class="teksteditorImg"  onmouseover="mouseover(this);" onmouseout="mouseout(this);"  onmousedown="mousedown(this);" onmouseup="mouseup(this);"  onclick="wrapWithLink(this.parentNode.parentNode.elements['txtnew']);">
  27.  
  28.             <textarea wrap="soft" name="txtnew" cols="85" rows="15" class="formfield" id="txtnew"  onSelect="storeCaret(this);" onClick="storeCaret(this);" onKeyUp="storeCaret(this);"><?php echo $paragr['tekst']?></textarea></td>
  29.           </tr>
  30.           <tr>
  31.             <td width="74"><div align="center">
  32.               </div></td>
  33.             <td width="304"><input name="m" type="hidden" value="<?php echo $m?>">
  34.               <input name="s" type="hidden" value="<?php echo $s?>">
  35.               <input name="wijzig_tekst" type="hidden" id="wijzig_tekst" value="<?php echo $paragr['artikel_id']?>">
  36.                &nbsp;
  37.                <input name="imageField" type="image" src="../images/bttns/bttn_OK_70x20_01.jpg" width="70" height="20" border="0">
  38. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </td>
  39.           </tr>
  40.         </table>
  41.         <br>&nbsp;
  42.       </form></td>
  43.     </tr>
  44.   </table>
  45. </div>

I hope somebody can help me...


Thanks in advance.

Regads,
Erwin
Oct 4 '05 #2
UniDyne
18 New Member
First off, I think this is in the wrong forum. This is JavaScript, not Java - there is a HUGE difference.

But, here is an answer anyway:

In the editor that works, this.parentNode .parentNode refers to the form tag - which is the parent of the textarea named "txt". This code works.

The problem is in the other half of your code. Here, this.parentNode .parentNode refers to the tr element - which is NOT the parent of the textarea named "newtxt".

You would do better to use document.getEle mentByID(), since your textareas use the id attribute. This would keep you from having to crawl up the DOM tree to find your textarea.
Oct 5 '05 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
6025
by: Will Seay | last post by:
At the end of this message I've pasted a script we're trying to modify slightly. I don't believe it is VBscript or javascript but these are the closest groups I could find with my limited programming knowledge. Basically, we are trying to add a few lines to this script that will execute a few shell commands (see comments at the very end of the code). We think this may be ActionScript2 but aren't sure. If you can offer any help, or know...
6
34170
by: Clay Beatty | last post by:
When you create database diagrams in Enterprise Manager, the details for constructing those diagrams is saved into the dtproperties table. This table includes an image field which contains most of the relevant infomation, in a binary format. SQL Enterprise manager offers no way to script out those diagrams, so I have created two Transact SQL components, one User Function and one User Procedure, which together provide a means to script...
12
2993
by: tshad | last post by:
I am not sure why I am getting this error: I have the following code I want to run from another include file that holds all my functions. functions.inc ************************************************************************************ <Script runat="Server"> Sub fnHeader(client As String) response.write("<!-- #include file = ../includes/staffingHeaders.inc -->")
17
7925
by: comp.lang.tcl | last post by:
The TCL command I am using will do a command-line action on a PHP script: set cannotRunPHP I have to do it this way as both the TCL script and the PHP script run as CLI. However, "info.php" requires user input to run; this causes the TCL script calling the PHP script to hose up and die. Is there a way I can do this so that the TCL script can call the PHP
19
3827
by: thisis | last post by:
Hi All, i have this.asp page: <script type="text/vbscript"> Function myFunc(val1ok, val2ok) ' do something ok myFunc = " return something ok" End Function </script>
5
2005
by: Bjorn Sagbakken | last post by:
Hello I have just migrated from VS 2003 to VS 2005, and .NET framework 1.1 to 2.0 I am at the end of debugging and fixing stuff. Now there is one error I just cannot find a solution to: On some pages I have applied a small client-script to trap the enter-key beeing pressed and re-route this action. With the new version this little script still works, it traps the enter-key. BUT it causes postback-errors on many other .NET control,...
15
3253
by: Lawrence Krubner | last post by:
Does anything about this script look expensive, in terms of resources or execution time? This script dies after processing about 20 or 25 numbers, yet it leaves no errors in the error logs. This is on a server that handles a fairly demanding site. The defaults, in php.ini, have all been cranked fairly high: scripts get 180 seconds to run, and they can have as much as 256 megs of RAM. The input for this script is coming from a textarea in...
3
4514
by: GazK | last post by:
I have been using an xml parsing script to parse a number of rss feeds and return relevant results to a database. The script has worked well for a couple of years, despite having very crude error-trapping (if it finds an error in one of the xml files, the script stops). Recently, the script has stopped working because one of the xml files is badly formed. So I decided to rewrite the script with better error trapping; the script should...
1
47483
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click on a link and after a moment or two a file download dialog box pops-up in your web browser and prompts you for some instructions, such as “open” or “save“. I’m going to show you how to do that using a perl script. What You Need Any recent...
7
16166
by: jeddiki | last post by:
Hi, As I am in Turkey at present, I can not see vidoes on youtube. So I have tried a few proxies but keep finding them slow or not working. So I have installed myphpProxy on my server under the domain name www.blog-start.com Unfortuantely it is not not working correctly
0
9416
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10032
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9979
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9849
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8861
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7393
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6661
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5293
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5433
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.