473,801 Members | 2,622 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Textarea ''wysiwyg'' bold etc

6 New Member
Hi folks, hope I'm in the wright section (I'm a newbie).

I've got a textarea that, with the click on a button, shows the html-look of the data in the textarea. This script I found on the net (with author source ).
Now I've added the option to make text in BOLD etc (code found on this forum), BUT it doesn't work....

This is the code (within a php file):

Expand|Select|Wrap|Line Numbers
  1. <div align="center">
  2. <table style="width:600px;border:solid 1px #959492;background:#ebebea">
  3. <tr><td valign="top">
  4. <form name="f" method="post">
  5. <textarea id="$key" name="$key" style="border:solid 1px #b9b8b6;padding:5px;width:300px;height:100px;scroll:auto;" $varwrap rows="$t_rows" cols="$t_cols" onkeyup=\"checktxtr("$key", $t_max, "dl$key");\"  class=formst>".$fields_val[$key]."
  6. <a href="http://www.thenetter.com/scripts/" target="_new">More Free Scripts</a> dododod
  7. </textarea>
  8.  
  9.  
  10.  
  11.  
  12. <table onMouseover="changeto(event, "lightyellow")" onMouseout="changeback(event, "silver")"><tr><td><font face="trebuchet, arial, HELVETICA" COLOR="#000099" size="-2"><b>
  13. <div id="dl$key"></div></b></font></td><td><font face="trebuchet, arial, HELVETICA" COLOR="#000099" size="-2"><b>".$msg2["chars_left"]."</b></font></td></tr></table> 
  14. <script language="javascript">checktxtr("$key", $t_max, "dl$key");</script>
  15.  
  16. <BR>
  17. <button onclick="window.document.f.$key.value='<BR>';preview.document.write (document.getElementsByName ('$key')[0].value); preview.document.close(); preview.focus()">Nieuwe regel</button>
  18.  
  19.  
  20. <input type="button" name="Button" value="B" onclick="ChangeText(this.f.$key,);" />&nbsp;<input type="button" name="Button" value="U" onclick="ChangeText(this.f.$key,;" />&nbsp; 
  21. <input type="button" name="Button" value="LINE" onclick="ChangeText(this.f.$key,[HR SIZE=1] [/HR];" />&nbsp;<input type="button" name="Button" value="SPACE" onclick="ChangeText(this.f.$key,<BR />;"/>&nbsp;
  22.  
  23.  
  24. </td><td valign="top">
  25. <iframe src="about:blank" name="preview" style="height:100px;width:300px;border:solid 1px #b9b8b6;background:#ffffff" frameborder="0">
  26. </iframe>
  27. </td>
  28. </tr>
  29. </table>
  30.  
  31. <!--    getElementByTagName ('TEXTAREA')[0].value);  -->
  32.  
  33. <button onclick="preview.document.write (document.getElementsByName ('$key')[0].value); preview.document.close(); preview.focus()">Voorbeschouwing</button>
  34. <button onclick="window.document.f.$key.value='';preview.document.write (document.getElementsByName ('$key')[0].value); preview.document.close(); preview.focus()">Clear All</button>
  35. <button onclick="window.location.href=window.location.href">Ververs</button>
  36. </div>
  37. </form>
Oct 4 '07 #1
5 2932
epots9
1,351 Recognized Expert Top Contributor
Hi sunadumari welcome to TSDN,

Please post the javascript functions checktxtr and changeback, i can't seem to find them in your code.

Also please use [code=html][/code] around html code and [code=javascrip t][/code] around javascript code.

thank you
Oct 4 '07 #2
sunadumari
6 New Member
Hi sunadumari welcome to TSDN,

Please post the javascript functions checktxtr and changeback, i can't seem to find them in your code.

Also please use around html code and around javascript code.

thank you


Allright.


They're not important as to my question, but here goes:


Expand|Select|Wrap|Line Numbers
  1. <script language='javascript'>
  2. <!--
  3. function checktxtr(txtrid, maxlngth, chrlr)
  4. {
  5. var txtr = document.forms['f'].elements[txtrid];
  6. var txtlngth = txtr.value.length;
  7. var chrlft = document.getElementById(chrlr);
  8.  
  9. if(txtlngth > maxlngth){txtr.value = txtr.value.substring(0, maxlngth); return;}
  10. chrlft.innerHTML = maxlngth- txtlngth;
  11. }
  12. --></script>
  13.  



Expand|Select|Wrap|Line Numbers
  1. function changeback(e,originalcolor){
  2. if (ie&&(event.fromElement.contains(event.toElement)||source.contains(event.toElement)||source.id=='ignore')||source.tagName=='TABLE')
  3. return
  4. else if (ns6&&(contains_ns6(source, e.relatedTarget)||source.id=='ignore'))
  5. return
  6. if (ie&&event.toElement!=source||ns6&&e.relatedTarget!=source)
  7. source.style.backgroundColor=originalcolor
  8. }
  9.  
Oct 4 '07 #3
gits
5,390 Recognized Expert Moderator Expert
hi ...

do you have a link to a testpage ... so that we may have a closer look at it?

and as far as i can see there should be an error on your posted code at line 12:

[HTML]<table onMouseover="ch angeto(event, "lightyello w")" onMouseout="cha ngeback(event, "silver")">[/HTML]
here you misuse the double quotes ... inside the doubles you could use single quotes or you should escape the double-ones ...

kind regards
Oct 4 '07 #4
sunadumari
6 New Member
Hi Folks,

I might have solved it: I used this script found at

http://www.sitemasters.be/?pagina=sc...&cat=17&id=177

BUT now it doesn't show the HTML-preview (iframe on the right)






[HTML]<HTML>

<HEAD>

</HEAD>

<BODY onload="preview .document.write (document.getEl ementsByName ('$key')[0].value); preview.documen t.close(); preview.focus() ">




<script language="javas cript">
function setCursor()
{
if(document.frm Post.$key.creat eTextRange)
{
document.frmPos t.$key.caretPos = document.select ion.createRange ().duplicate();
}
}

function ubb(begin,eind, opmaak)
{
if(!eind && !opmaak)
{
if(document.frm Post.$key.creat eTextRange && document.frmPos t.$key.caretPos )
{
document.frmPos t.$key.caretPos .text = begin;
}
}

else if(opmaak == "dubbel")
{
var selectie = document.select ion.createRange ().text;
if(!selectie)
{
var url_deel = prompt("Typ hier de/het "+ begin +" die/dat geplaatst moet worden:","");
var tekst_deel = prompt("Typ hier de tekst die geplaatst moet worden:","");
if(url_deel && tekst_deel)
{
document.frmPos t.$key.caretPos .text = "["+begin+"="+url _deel+"]" + tekst_deel + "[/"+eind+"]";
}
}

if(selectie)
{
var url_deel = prompt("Typ hier de url die geplaatst moet worden:","");
if(url_deel)
{
document.select ion.createRange ().text = "["+begin+"="+url _deel+"]" + selectie + "[/"+eind+"]";
}
}
}

else
{
if(opmaak != "geen")
{
var selectie = document.select ion.createRange ().text;
if(!selectie)
{
var new_inhoud = prompt("Typ hier de tekst in waarrond "+begin+" & "+eind+" geplaatst moet worden:","");
if(new_inhoud)
{
document.frmPos t.$key.caretPos .text = begin + new_inhoud + eind;
}
}

if(selectie)
{
document.select ion.createRange ().text = begin + selectie + eind;
}
}
}

document.frmPos t.$key.focus();
return;
}
</script>





<!-- Paste this code into the BODY section of your HTML document -->


<form name="f" method="post">
<div align="center">

<table style="width:60 0px;border:soli d 1px #959492;backgro und:#ebebea">
<tr>
<td colspan="21" align="center">

<textarea name="$key" $varwrap rows="$t_rows" cols="$t_cols" style="border:s olid 1px #b9b8b6;padding :5px;width:300p x;height:100px; scroll:auto;" onkeyup=\"check txtr("$key", $t_max, "dl$key");\ " class=formst onkeyup="setCur sor();" onkeydown="setC ursor();" onfocus="setCur sor();" onclick="setCur sor();">".$fiel ds_val[$key]."<a href="http://www.thenetter.c om/scripts/" target="_new">M ore Free Scripts</a> dododod</textarea>


<table onMouseover="ch angeto(event, "lightyello w")" onMouseout="cha ngeback(event, "silver")"><tr> <td><font face="trebuchet , arial, HELVETICA" COLOR="#000099" size="-2"><b>
<div id="dl$key"></div></b></font></td><td><font face="trebuchet , arial, HELVETICA" COLOR="#000099" size="-2"><b>".$msg 2["chars_left "]."</b></font></td></tr></table>
<script language="javas cript">checktxt r("$key", $t_max, "dl$key");</script>

</TD><TD>
<iframe src="about:blan k" name="preview" style="height:1 00px;width:300p x;border:solid 1px #b9b8b6;backgro und:#ffffff" frameborder="0" >
</iframe>
<BR>
<!-- getElementByTag Name ('TEXTAREA')[0].value); -->

<button onclick="previe w.document.writ e (document.getEl ementsByName ('$key')[0].value); preview.documen t.close(); preview.focus() ">Voorbeschouwi ng</button>
<button onclick="window .document.f.$ke y.value='';prev iew.document.wr ite (document.getEl ementsByName ('$key')[0].value); preview.documen t.close(); preview.focus() ">Clear All</button>
<button onclick="window .location.href= window.location .href">Ververs</button>
</div>
</TD></TR>

<TR>

<td colspan="21" align="center">
<img src='left.gif' width="20" height="20" onclick="ubb('
','
','URL invoegen');">
<img src='center.gif ' width="20" height="20" onclick="ubb('
','
','URL invoegen');">
<img src='right.gif' width="20" height="20" onclick="ubb('
','
','URL invoegen');">
<img src='b.gif' width="20" height="20" onclick="ubb('','','URL invoegen');">
<img src='i.gif' width="20" height="20" onclick="ubb('','','URL invoegen');">
<img src='u.gif' width="20" height="20" onclick="ubb('','','URL invoegen');">
</td></TR></TABLE>

</form>



</BODY>
</HTML>[/HTML]
Oct 4 '07 #5
sunadumari
6 New Member
Hi folks,

at this time I'm using this now





[HTML]<HTML>

<HEAD>



<script language="javas cript">
function setCursor()
{
if(document.f.$ key.createTextR ange)
{
document.f.$key .caretPos = document.select ion.createRange ().duplicate();
}
}

function ubb(begin,eind, opmaak)
{
if(!eind && !opmaak)
{
if(document.f.$ key.createTextR ange && document.f.$key .caretPos)
{
document.f.$key .caretPos.text = begin;
}
}

else if(opmaak == "dubbel")
{
var selectie = document.select ion.createRange ().text;
if(!selectie)
{
var url_deel = prompt("Typ hier de/het "+ begin +" die/dat geplaatst moet worden:","");
var tekst_deel = prompt("Typ hier de tekst die geplaatst moet worden:","");
if(url_deel && tekst_deel)
{
document.f.$key .caretPos.text = "["+begin+"="+url _deel+"]" + tekst_deel + "[/"+eind+"]";
}
}

if(selectie)
{
var url_deel = prompt("Typ hier de url die geplaatst moet worden:","");
if(url_deel)
{
document.select ion.createRange ().text = "["+begin+"="+url _deel+"]" + selectie + "[/"+eind+"]";
}
}
}

else
{
if(opmaak != "geen")
{
var selectie = document.select ion.createRange ().text;
if(!selectie)
{
var new_inhoud = prompt("Typ hier de tekst in waarrond "+begin+" & "+eind+" geplaatst moet worden:","");
if(new_inhoud)
{
document.f.$key .caretPos.text = begin + new_inhoud + eind;
}
}

if(selectie)
{
document.select ion.createRange ().text = begin + selectie + eind;
}
}
}

document.f.$key .focus();
return;
}
</script>


</HEAD>

<BODY>

<?PHP include ("ubb.php"); ?>











<script type="text/javascript">

function showHTML () {

// ref textarea
textarea1 = document.getEle mentById('$key' );
// where to view HTML code
viewHtml = document.getEle mentById('div1' );
// Finally get HTML output in div
viewHtml.innerH TML = textarea1.value ;

}
</script>





<!-- Paste this code into the BODY section of your HTML document -->


<form name="f" method="post">
<div align="center">

<table style="width:60 0px;border:soli d 1px #959492;backgro und:#ebebea">
<tr>
<td colspan="21" align="center">

<textarea name="$key" id="$key" onkeyup="showHT ML()" $varwrap rows="$t_rows" cols="$t_cols" style="border:s olid 1px #b9b8b6;padding :5px;width:300p x;height:100px; scroll:auto;" onkeydown=\"che cktxtr("$key", $t_max, "dl$key");\ " class=formst onfocus="setCur sor();" onclick="setCur sor();">".$fiel ds_val[$key]."
<B>dododod
</textarea>


<table onMouseover="ch angeto(event, "lightyello w")" onMouseout="cha ngeback(event, "silver")"><tr> <td><font face="trebuchet , arial, HELVETICA" COLOR="#000099" size="-2"><b>
<div id="dl$key"></div></b></font></td><td><font face="trebuchet , arial, HELVETICA" COLOR="#000099" size="-2"><b>".$msg 2["chars_left "]."</b></font></td></tr></table>
<script language="javas cript">checktxt r("$key", $t_max, "dl$key");</script>

</TD><TD>
<div id="div1" name="div1"
style="position :relative;width :350px;height:2 00px;border:1px solid
red;overflow:au to"></div>

<input type="button" onclick="showHT ML()" value="Voorbesc houwing" />
<button onclick="window .location.href= window.location .href">Ververs</button>

<!-- <iframe src="about:blan k" name="preview" style="height:1 00px;width:300p x;border:solid 1px #b9b8b6;backgro und:#ffffff" frameborder="0" > -->
<!-- </iframe> -->
<BR>
<!-- getElementByTag Name ('TEXTAREA')[0].value); -->


</div>
</TD></TR>

<TR>

<td colspan="21" align="center">
<img src='left.gif' width="20" height="20" onclick="ubb('< left>','</left>','URL invoegen');">
<img src='center.gif ' width="20" height="20" onclick="ubb('[center]','</center>','URL invoegen');">
<img src='right.gif' width="20" height="20" onclick="ubb('< right>','</right>','URL invoegen');">
<img src='b.gif' width="20" height="20" onclick="ubb('< b>','</b>','URL invoegen');">
<img src='i.gif' width="20" height="20" onclick="ubb('< i>','</i>','URL invoegen');">
<img src='u.gif' width="20" height="20" onclick="ubb('< u>','</u>','URL invoegen');">
</td></TR></TABLE>

</form>



</BODY>
</HTML>[/HTML]

it works well, but it seems that it doesn't ''activatel'' the ubb.php file that works as a safeguard (I don't want <a href and <img etc etc in the textarea....)

If anyone needs to see the ubb.php let me know, I'll post it here.

Anyone a clue how to get a safeguard around this?!
Oct 4 '07 #6

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

Similar topics

5
4911
by: Piotr Wolski | last post by:
how can i format textarea? f.e.: <textarea><b>i wqant this text to be bold</b></textarea>
2
1682
by: Lindsey | last post by:
Hi I am wondering if anyone can help. We have a form used by a client to add news to a database, however at the moment the text edited is bog standard and the user can not bold or color the text. I have seen in email applications such as hotmail and yahoo, that when you create a new email there is a menu above which when you highlight
2
2469
by: Michael | last post by:
Question 1 ---------------- I am writing an advanced BBCode system for my forums and I would like to be able to find where the cursor was positioned last in the text so I could insert the BBCode there. Question 2 ---------------- Again I am writing an advanced BBCode system for my forums and I would like to make is so that when someone puts in a tag it goes bold, so
8
7426
by: firewood | last post by:
I am developing a form-based website development system using PHP5, and I want to incorporate a secure, reliable, Wysiwyg textarea script in place of the standard, unformatable, text-only textarea one gets with a <textarea> tag. All I need are basic formatting tools - bold, italics, underline, lists, tables. I've looked into a few already with spotty results: SPAW - is buggy with PHP5. Textarearich - is awkward to configure, and I'm...
9
3157
by: TristaSD | last post by:
Hi, Does anyone know where I can get a decent WYSIWYG text area editor to use on one of my sites? The goal is to accomodate users who know zero html and to insert blog-like enties into the database already formatted with html tags. Just thought I'd try this first before I go into WordPress and try to tear out their editor :)
2
2906
by: dennis.sprengers | last post by:
Ik ben bezig met een eigen UBB editor. Als iemand aan het typen is, zorgt CTRL-B voor een \-tag en nogmaals CTRL-B voor een \ tag. Als je eerst een selectie maakt en dan CTRL-B drukt, wordt de selectie ingesloten door \ en \, net als hier op GoT. Wat ik nu probeer is, om de B-knop uit de toolbar te laten oplichten als de cursor op een woord staat dat omgeven is door B-tags: I'm trying to write my own UBB editor. If a user types...
3
2701
kendall
by: kendall | last post by:
I'm currently working on a PHP CMS for my school that uses simple forms to update the pages and database. To get it out in use, it will have to be usable by people who don't know that is bold, and all the rest of it. I have noticed that vBulletin has the best formatting buttons (and no, I'm not talking about the WYSIWYG editor, I know that's way beyond me) so I was thinking of something similar (if I get bold, italic and underlined working, I'm...
2
3808
by: olddocks | last post by:
i am planning on kind of editor by replacing the textarea with iframe so that i could edit the content with rich html. I am facing weird problem and i cannot set the value of iframe innerHTML with the value of textarea while loading. The idea is hide the textarea after moving the value to iframe rich text editor. what could be the problem. here is the code var myeditor;
0
2289
by: saijin | last post by:
I'm planning to call a list of data from an XML file but when I duplicate the content inside the <data></data> it is not showing anything Here's the ActionScript 3.0 import fl.controls.ComboBox; import fl.controls.TextArea; import fl.containers.UILoader;
0
9698
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10295
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
10271
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
10054
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
9105
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
7593
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
6832
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();...
2
3782
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2961
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.