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
 
Check vituz post :

thread216-144664 Regards

Big Dave

davidbyng@hotmail.com


** If I am wrong I am sorry, but i'm only trying to help!! **

 
Vituz's post is nice and I can use that code too!

Does anyone know anything similar that will allow users to create their own links? Like the user specifying the <a> URL and link text separately as in <a href=&quot; Here</a> ... Perhaps if they could specify the target too, that would be nice.
 
check out :

faq333-1287 How can I format users input (for a forum entry etc) ? Regards

Big Dave

davidbyng@hotmail.com


** If I am wrong I am sorry, but i'm only trying to help!! **

 
Dave, thanks for your quick response. The FAQ is just what I needed and it works great!

As for vituz's code for formatting text, when I set up the receiving page, Response.write literally writes verbatim test and not the desired results. Any ideas on what to put on the receiving page? Hopefully vituz is reading this right now <fingers crossed>.
 
All you need to do is :

<%
my_thing = Request.Form(&quot;my_stuff&quot;)
function myreplace()
my_thing = Replace(my_thing, &quot;&quot;, &quot;<b>&quot;)
my_thing = Replace(my_thing, &quot;
&quot;, &quot;</b>&quot;)
myreplace = my_thing
end function
Response.Write myreplace()
%>[color] Regards

Big Dave

davidbyng@hotmail.com


** If I am wrong I am sorry, but i'm only trying to help!! **

 
Oops this form has chaned my code, i'll try again :

Code:
<%
my_thing = Request.Form(&quot;my_stuff&quot;)
function myreplace()
  my_thing = Replace(my_thing, &quot;[b]&quot;, &quot;<b>&quot;)
  my_thing = Replace(my_thing, &quot;[/b]&quot;, &quot;</b>&quot;)
  myreplace = my_thing
end function
Response.Write myreplace()
%>
Regards

Big Dave

davidbyng@hotmail.com


** If I am wrong I am sorry, but i'm only trying to help!! **

 
In the myreplace() function, do I just keep making Replaces for the rest of the formatting options, too?

i.e.:
to <i>
to </i>
to <u>
to </u>

...and so on and so on? Any idea how it would be done with the colors?
 
I tested the code from thread on Mac with IE 5 and recieved the following error:

Microsoft JScript runtime error
&quot;null&quot; is not an object

this referred to the following line of code

sel=(IE)?doument.selection;(NC)?document.getSelection():null

The script work fine on PC but not on mac. This is from Thread216-144664.

<script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;>
<!--
var IE=document.all || document.getElementById
var NC=document.layers

function Inserty(){
var prestart,preend,start,end,sel,range,thetext,dvsn,colname,theform,formname,colselname,colsel,effselname,effsel,effname,eff
formname=&quot;myne&quot;
colselname=&quot;colorName&quot;
effselname=&quot;effectName&quot;
theform=document.forms[formname]
colsel=theform[colselname]
effsel=theform[effselname]
colname=colsel.options[colsel.selectedIndex].value
effname=effsel.options[effsel.selectedIndex].text
eff=effsel.options[effsel.selectedIndex].value

dvsn=[&quot;[&quot;,&quot;]&quot;,&quot;[/&quot;]
prestart=&quot;&quot;
preend=&quot;&quot;

if (colname!='none'){
prestart=dvsn[0]+'color '+colname+dvsn[1]
preend=dvsn[2]+'color'+dvsn[1]
}

start=(effname!='color')?prestart+dvsn[0]+eff+dvsn[1]:prestart
end=(effname!='color')?dvsn[2]+eff+dvsn[1]+preend:preend

sel=(IE)?document.selection:(NC)?document.getSelection():null
range=sel.createRange()
thetext=range.text
if (thetext.length){
range.text=start+thetext+end
}}
//-->
</script>

I would appreciate any help to make these code work on MAC or any reference to other codes do do the same function that work on mac.

many thanks.

Christian Becker
cbecker@sarasotamagazine.com
 
Yes you can add as many things into the function as you like. Regards

Big Dave

davidbyng@hotmail.com


** If I am wrong I am sorry, but i'm only trying to help!! **

 
Yes, I found that out. Check out the code ...(also, some questions below)

<%
my_thing = Request.Form(&quot;txtar&quot;)
function myreplace()
my_thing = Replace(my_thing, &quot;[]&quot;, &quot;&quot;)
my_thing = Replace(my_thing, &quot;[/]&quot;, &quot;&quot;)
my_thing = Replace(my_thing, &quot;&quot;, &quot;<b>&quot;)
my_thing = Replace(my_thing, &quot;
&quot;, &quot;</b>&quot;)
my_thing = Replace(my_thing, &quot;&quot;, &quot;<i>&quot;)
my_thing = Replace(my_thing, &quot;
&quot;, &quot;</i>&quot;)
my_thing = Replace(my_thing, &quot;&quot;, &quot;<s>&quot;)
my_thing = Replace(my_thing, &quot;
&quot;, &quot;</s>&quot;)
my_thing = Replace(my_thing, &quot;&quot;, &quot;<u>&quot;)
my_thing = Replace(my_thing, &quot;
&quot;, &quot;</u>&quot;)
my_thing = Replace(my_thing, &quot;&quot;, &quot;<font color=green>&quot;)
my_thing = Replace(my_thing, &quot;&quot;, &quot;<font color=red>&quot;)
my_thing = Replace(my_thing, &quot;&quot;, &quot;<font color=gray>&quot;)
my_thing = Replace(my_thing, &quot;&quot;, &quot;<font color=blue>&quot;)
my_thing = Replace(my_thing, &quot;
&quot;, &quot;</font>&quot;)
myreplace = my_thing
end function
Response.Write myreplace()
%>

==
I can do the same thing with more colors and fonts, too! :)

QUESTIONS:

See how I had to replace &quot;[]&quot; to &quot;&quot; and &quot;[/] to &quot;&quot; ...I did that because I also want a &quot;None&quot; value like in the colorName field for the effectName field. But when you click on &quot;effect,&quot; the value of &quot;&quot; will still post as [][/] in the textarea of originating page. Have any idea how I can get a true null value of &quot;&quot; and not [][/] in the textarea?

Also, do you happen to know how I can get carriage returns to work on the receiving page?
 
christianbecker and Rothdavid, I hope someone can help you out with Mac compatibility. Rothdavid, sorry I had so many questions in your thread.
 
Yes carriage returns are easy peasy :

Code:
<%
my_thing = Request.Form(&quot;txtar&quot;)
function myreplace()
  my_thing = Replace(my_thing, &quot;[]&quot;, &quot;&quot;)
  my_thing = Replace(my_thing, &quot;[/]&quot;, &quot;&quot;)
  my_thing = Replace(my_thing, &quot;[b]&quot;, &quot;<b>&quot;)
  my_thing = Replace(my_thing, &quot;[/b]&quot;, &quot;</b>&quot;)
  my_thing = Replace(my_thing, &quot;[i]&quot;, &quot;<i>&quot;)
  my_thing = Replace(my_thing, &quot;[/i]&quot;, &quot;</i>&quot;)
  my_thing = Replace(my_thing, &quot;[s]&quot;, &quot;<s>&quot;)
  my_thing = Replace(my_thing, &quot;[/s]&quot;, &quot;</s>&quot;)
  my_thing = Replace(my_thing, &quot;[u]&quot;, &quot;<u>&quot;)
  my_thing = Replace(my_thing, &quot;[/u]&quot;, &quot;</u>&quot;)
  my_thing = Replace(my_thing, &quot;[COLOR=green]&quot;, &quot;<font color=green>&quot;)
  my_thing = Replace(my_thing, &quot;[COLOR=red]&quot;, &quot;<font color=red>&quot;)
  my_thing = Replace(my_thing, &quot;[COLOR=gray]&quot;, &quot;<font color=gray>&quot;)
  my_thing = Replace(my_thing, &quot;[COLOR=blue]&quot;, &quot;<font color=blue>&quot;)
  my_thing = Replace(my_thing, &quot;[/color]&quot;, &quot;</font>&quot;)
  my)thing = Replace(my_thing, VBcrlf, &quot;<br />&quot;)
  myreplace = my_thing
end function
Response.Write myreplace()
%>

Note the VBcrlf is VBScript code for carriage return Regards

Big Dave

davidbyng@hotmail.com


** If I am wrong I am sorry, but i'm only trying to help!! **

 
Anyone know the answer to the crapintosh dilema?? Regards

Big Dave

davidbyng@hotmail.com


** If I am wrong I am sorry, but i'm only trying to help!! **

 
woops, sorry guyz, my fault, i thought this thread is solved, as there were reply's.. :(

ok, lets see how could i change the code for your demands..

btw, javascript solution for link:

var str=&quot;text&quot;
var theurl=&quot;str=str.link(theurl);

i'll let you know when would be ready Victor
 
well, here is new (updated) code:

it would insert <b> (& others) instead of [ignore][/ignore] & <font color=red> instead of [ignore][/ignore]
i also added none to effects, & now it won't add empty brackets

as for Mac's - sorry, not today, our macs are busy, & guyz here won't let me play with my scripts there :(
but as error was in browser checking string, i've modifyed it a bit..

cr's - i think Dave's right, but i can add one suggestion: write all of this stuff to <pre> tags, then data would have cr's & other user's formatting stuff included

ok, lets see the code:
~~~~~~~~~~~~~~~~~
<html><head><title>generate your post :)</title>
<script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;>
<!--
var IE=(document.all || document.getElementById)?true:false;
var NC=(document.layers)?true:false;


function Inserty(){
var prestart, preend, start, end, sel, range, thetext, dvsn, colname, theform, formname, colselname, colsel, effselname, effsel, effname, eff
formname=&quot;myne&quot;
colselname=&quot;colorName&quot;
effselname=&quot;effectName&quot;
theform=document.forms[formname]
colsel=theform[colselname]
effsel=theform[effselname]
colname=colsel.options[colsel.selectedIndex].value
effname=effsel.options[effsel.selectedIndex].text
eff=effsel.options[effsel.selectedIndex].value

dvsn=[&quot;<&quot;,&quot;>&quot;,&quot;</&quot;]
prestart=&quot;&quot;
preend=&quot;&quot;

if (colname!='none'){
prestart=dvsn[0]+'font color='+colname+dvsn[1]
preend=dvsn[2]+'font'+dvsn[1]
}

start=(effname!='color' && eff!='none')?prestart+dvsn[0]+eff+dvsn[1]:prestart
end=(effname!='color' && eff!='none')?dvsn[2]+eff+dvsn[1]+preend:preend

sel=(IE)?document.selection:(NC)?document.getSelection():null
range=sel.createRange()
thetext=range.text
if (thetext.length){
range.text=start+thetext+end
}}
//-->
</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;>
<select name=&quot;effectName&quot;>
<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>
<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>
</form>
</body>
</html>
~~~~~~~~~~~~~~~~~

changed (updated) code was bolded & redLighted

what else? [sub](i'm shure this attempt won't be successfull from the first shot)[/sub] Victor
 
Thanks Victor for trying to modify the code for mac. I tried it but it still not functioning. I am a beginner with asp and an absolute novice with js but after researching this problem on the net i have come across the following info that might be useful as to why it wont work on mac ie5.

document.selection object is unimplemented in Mac IE 5 but document.getSelection is according to info from this url:


I tried the obvious of replacing document.selection with document.getselection in the code with no luck.

FYI

Christian
 
We've had so many problems with Javascript and Macs that my boss just told one of our clients yesterday that we would NOT make any changes to get code that works fine in IE5.0 and above, and NS4.7 and above to work on a Mac. They have a PC they can use with it. I'm not sure why, because the js code I wrote doesn't do that much that's tricky, and I stayed away from any js1.2 extensions, but it just doesn't work on a Mac. Too bad, for the Mac. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top