Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WRITE ME A SCRIPT PLEASE !!!!

Status
Not open for further replies.

Rothdavid

IS-IT--Management
Nov 26, 2001
2
US
Hi:

I need a script that will allow me to add HTML bold and Italic, and underline tags inside a form field.

I have one that works great on a PC but doesn't work at all on a mac and Im not a scripter. Would be happy to send it to you for you to check out?

Its for an editorial archive. Our editors add stories to the web site and as the fill in an ASP form, they copy the text body into a field then need to be able to Bold, Italics and Underline words inside the field so when its recalled, the text is formatted with B, I & U if needed.

The script I have works well on a PC but will not work at all on a mac, its three simple buttons. The user highlights the text then hits the B, I or U button and the script inserts the tags in the text body on either side of the selected text.

Any help would be greatly appreciated.

David
 
vituz (or anyone else who knows),

The code works great! THANK YOU! Maybe I should leave well enough alone :) but is there any way for the textarea field to be WYSIWYG?
 
You can make it a wysiwyg textarea with an activex object (same as the one used in hotmail in fact you can modify / half inch that one) Regards

Big Dave

davidbyng@hotmail.com

 
i don't think so..
but you might try to put its content into the layer (division):

~~~~~~~~~~~
<html><head><title>another try</title>
<style>
<!--
#preview{
position:relative;
text-align:center;
border:1px solid;
}
-->
</style>
<script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;>
<!--
var IE=(document.all || document.getElementById)?true:false;
var NC=(document.layers)?true:false;

var formname, txtarname, theform, thetxtar, colname, theform, colselname, colsel, effselname, effsel, effname, eff, postTypename, opostType, vpostType, insemptyname, insempty
var yes=1, no=0
//this would write error message if nothing was selected
var withError=no
var errmessage=&quot;select something&quot;;

onload=function(){
formname=&quot;myne&quot;
colselname=&quot;colorName&quot;
effselname=&quot;effectName&quot;
txtarname=&quot;txtar&quot;
postTypename=&quot;_type&quot;
insemptyname=&quot;insertempty&quot;

theform=document.forms[formname]
}

//wha: 1 - value; 0 - text
function getSelValue(selobj,wha){
var mul=selobj.type.match(/multi/)
if (mul){
var selected=[]
for (var ii=0; ii<selobj.options.length; ii++){
if (selobj.options[ii].selected==true){
selected[selected.length] = (wha) ? selobj.options[ii].value : selobj.options[ii].text
}}}
return (mul) ? selected : (wha) ? selobj.options[selobj.selectedIndex].value : selobj.options[selobj.selectedIndex].text;
}

function Inserty(){
var prestart, preend, start, end, sel, range, thetext, dvsn,

colsel=theform[colselname]
effsel=theform[effselname]
opostType=theform[postTypename]
colname=getSelValue(colsel,1);
effname=getSelValue(effsel,0);
eff=getSelValue(effsel,1);
vpostType=parseInt(getSelValue(opostType,1))
insempty=theform[insemptyname].checked

dvsn = (vpostType) ? [&quot;<&quot;,&quot;>&quot;,&quot;</&quot;] : [&quot;[&quot;,&quot;]&quot;,&quot;[/&quot;]

prestart=&quot;&quot;
preend=&quot;&quot;
start=&quot;&quot;
end=&quot;&quot;

if (colname!='none'){
var colpre = (vpostType) ? &quot;font color=&quot; : &quot;color &quot;
var colpost = (vpostType) ? &quot;font&quot; : &quot;color&quot;
prestart=dvsn[0]+colpre+colname+dvsn[1]
preend=dvsn[2]+colpost+dvsn[1]
}

//added by lumberjakel, for insertion if even nothing is selected
myne.txtar.focus();

sel=(IE)?document.selection:(NC)?document.getSelection():null
range=sel.createRange()
thetext=range.text

if (eff.length){
//multiple effect
for (var ii=0; ii<eff.length; ii++){
start+=(effname[ii]!='color' && eff[ii]!='none' && !thetext.match(eff[ii])) ? dvsn[0]+eff[ii]+dvsn[1] : &quot;&quot;
end+=(effname[effname.length-(ii+1)]!='color' && eff[eff.length-(ii+1)]!='none' && !thetext.match(eff[eff.length-(ii+1)])) ? dvsn[2]+eff[eff.length-(ii+1)]+dvsn[1] : &quot;&quot;
}
start = (!thetext.match(prestart)) ? prestart+start : start
end += (!thetext.match(preend)) ? preend : &quot;&quot;
} else {
//one effect
start=(effname!='color' && eff!='none')?prestart+dvsn[0]+eff+dvsn[1]:prestart
end=(effname!='color' && eff!='none')?dvsn[2]+eff+dvsn[1]+preend:preend
}


if (insempty){
if (withError){
range.text = (thetext) ? start+thetext+end : (start && end) ? start+end : errmessage ;
} else {
range.text = (thetext) ? start+thetext+end : start+end;
}
}
else{
if (thetext.length){
range.text=start+thetext+end
}
}
}

function preview(){
var divsn=document.getElementById(&quot;preview&quot;)
thetxtar=theform[txtarname]
divsn.innerHTML=&quot;<pre>&quot;+thetxtar.value+&quot;</pre>&quot;
}
//-->
</script>
</head>

<body>
<form name=myne>
<textarea name=&quot;txtar&quot; cols=60 rows=14 wrap=virtual>
</textarea><br>
<input type=&quot;button&quot; name=&quot;b1&quot; value=&quot;effect&quot; onclick=&quot;Inserty()&quot;>
effect: <select name=&quot;effectName&quot; multiple size=3 align=top>
<option value='none' selected>None
<option value='b'>bold
<option value='i'>italics
<option value='u'>underline
<option value='s'>strike through
<option value='color'>color
</select>
color: <select name=&quot;colorName&quot;>
<option value='none' selected>None
<option value='green'>Green
<option value='red'>Red
<option value='grey'>Grey
<option value='blue'>Blue
</select>
effect type: <select name=&quot;_type&quot;>
<option value=0 selected>TT tgml
<option value=1>html
</select>
<br>
<input type=checkbox name=insertempty> Insert when nothing is selected<br>
<center><input type=button value=&quot; preview it &quot; onclick=&quot;preview()&quot;><input type=reset value=&quot; clear &quot;></center>
</form>
<p align=center>The preview would appear here: (below)
<div id=&quot;preview&quot; >
nothing yet
</div>
</body>
</html>
~~~~~~~~~~~ Victor
 
sorry Dave, i didn't saw your post when was submitting myne

saying i don't think so i meant Peacemaker's question, but not your answer
Victor
 
Check out this WYSIWYG text formatting editor I found!


I replicated it at the above URL for testing (so test away). My problem is that I can't seem to receive any data on the next page after clicking &quot;Post!&quot;. Go ahead and try. Any help here would be appreciated! :)

This WYSIWYG form editor is really cool but I also need it to do colors (that's what I like about vituz's script). Maybe as a third drop-down list similar to the &quot;Font&quot; and &quot;Size&quot; drop-downs. Any ideas there?

So that's two helps I need:
1. How to receive
2. Colors

Thank you!
 
Hey, I have tested this and it does not work on the MAC at all. I can't even get into the text box to type anything to try to use the buttons.

Its close to what we need but not quite. I am looking for something that will paste HTML Tags around the highlighted text because its stored with tags in the database. When the record is accessed, the tags then are read as HTML and then the formatting is applied.

The WYSIWYG thing is cool but I don't kwow if its doing what we need it to do.

Im not a programmer so I can't offer much help on your problems but I have my programmer reviewing all these threads as they come in and have asked he help when he can.

Thanks for trying

David
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top