473,385 Members | 1,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Textarea ''wysiwyg'' bold etc

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 2907
epots9
1,351 Expert 1GB
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=javascript][/code] around javascript code.

thank you
Oct 4 '07 #2
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 Expert Mod 4TB
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="changeto(event, "lightyellow")" onMouseout="changeback(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
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.getElementsByName ('$key')[0].value); preview.document.close(); preview.focus()">




<script language="javascript">
function setCursor()
{
if(document.frmPost.$key.createTextRange)
{
document.frmPost.$key.caretPos = document.selection.createRange().duplicate();
}
}

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

else if(opmaak == "dubbel")
{
var selectie = document.selection.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.frmPost.$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.selection.createRange().text = "["+begin+"="+url_deel+"]" + selectie + "[/"+eind+"]";
}
}
}

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

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

document.frmPost.$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:600px;border:solid 1px #959492;background:#ebebea">
<tr>
<td colspan="21" align="center">

<textarea name="$key" $varwrap rows="$t_rows" cols="$t_cols" style="border:solid 1px #b9b8b6;padding:5px;width:300px;height:100px;scrol l:auto;" onkeyup=\"checktxtr("$key", $t_max, "dl$key");\" class=formst onkeyup="setCursor();" onkeydown="setCursor();" onfocus="setCursor();" onclick="setCursor();">".$fields_val[$key]."<a href="http://www.thenetter.com/scripts/" target="_new">More Free Scripts</a> dododod</textarea>


<table onMouseover="changeto(event, "lightyellow")" onMouseout="changeback(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>".$msg2["chars_left"]."</b></font></td></tr></table>
<script language="javascript">checktxtr("$key", $t_max, "dl$key");</script>

</TD><TD>
<iframe src="about:blank" name="preview" style="height:100px;width:300px;border:solid 1px #b9b8b6;background:#ffffff" frameborder="0">
</iframe>
<BR>
<!-- getElementByTagName ('TEXTAREA')[0].value); -->

<button onclick="preview.document.write (document.getElementsByName ('$key')[0].value); preview.document.close(); preview.focus()">Voorbeschouwing</button>
<button onclick="window.document.f.$key.value='';preview.d ocument.write (document.getElementsByName ('$key')[0].value); preview.document.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
Hi folks,

at this time I'm using this now





[HTML]<HTML>

<HEAD>



<script language="javascript">
function setCursor()
{
if(document.f.$key.createTextRange)
{
document.f.$key.caretPos = document.selection.createRange().duplicate();
}
}

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

else if(opmaak == "dubbel")
{
var selectie = document.selection.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.selection.createRange().text = "["+begin+"="+url_deel+"]" + selectie + "[/"+eind+"]";
}
}
}

else
{
if(opmaak != "geen")
{
var selectie = document.selection.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.selection.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.getElementById('$key');
// where to view HTML code
viewHtml = document.getElementById('div1');
// Finally get HTML output in div
viewHtml.innerHTML = 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:600px;border:solid 1px #959492;background:#ebebea">
<tr>
<td colspan="21" align="center">

<textarea name="$key" id="$key" onkeyup="showHTML()" $varwrap rows="$t_rows" cols="$t_cols" style="border:solid 1px #b9b8b6;padding:5px;width:300px;height:100px;scrol l:auto;" onkeydown=\"checktxtr("$key", $t_max, "dl$key");\" class=formst onfocus="setCursor();" onclick="setCursor();">".$fields_val[$key]."
<B>dododod
</textarea>


<table onMouseover="changeto(event, "lightyellow")" onMouseout="changeback(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>".$msg2["chars_left"]."</b></font></td></tr></table>
<script language="javascript">checktxtr("$key", $t_max, "dl$key");</script>

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

<input type="button" onclick="showHTML()" value="Voorbeschouwing" />
<button onclick="window.location.href=window.location.href ">Ververs</button>

<!-- <iframe src="about:blank" name="preview" style="height:100px;width:300px;border:solid 1px #b9b8b6;background:#ffffff" frameborder="0"> -->
<!-- </iframe> -->
<BR>
<!-- getElementByTagName ('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
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
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...
2
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...
8
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...
9
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...
2
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...
3
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...
2
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...
0
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.