View Full Version : cross browser wysiwyg

12-17-2004, 08:12 PM
hi all, this is the usuall "my first javascript" post.
I'm trying to make a wysiwyg textarea..
my example page (http://www.boogiestick.com/wysiwyg/)
very simple script.. i have two ways to go about it.
the first two functions work but the prompt one does not, I have played with different variations but basically.. i don't know javascript.
I usually use asp, php but its time I learn javascript.

<script type="text/JavaScript">
function addURL(form)
{form.news.value= form.news.value+" <a href=\""+form.newstext.value+"\">"+form.urllink.value+"</a>";}

function addBold(form)
{form.news.value= form.news.value+" <b>"+form.btext.value+"</b>";}

function boldText(bt)
var name=prompt("enter bold text");
this.form.newstext.value=form.newstext.value+" <b>"+name+"</b>";
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<form name="form1" method="post" action="examples/test.asp">
<input name="urllink" type="text" value="" id="urllink">text<br>
<input name="newstext" type="text" value="http://" id="newstext">url<br>
<input name="same" type="button" class="button" id="same" onClick="addURL(this.form)" value="add it"><br>
<input name="btext" type="text" value="" id="btext">text<br>
<input name="same" type="button" class="button" id="same" onClick="addBold(this.form)" value="add it"><br>
<textarea name="news" rows="15" cols="45"><b>text</b></textarea><br>
<input type="submit" name="Submit" value="Submit">
<form name="form2" method="post" action="examples/test.asp">
<input name="bbtt" type="button" class="button" id="bbtt" onClick="boldText('bt');" value="boldText"><br />
<textarea name="newstext" rows="15" cols="45" id="newstext"></textarea>

Willy Duitt
12-17-2004, 08:24 PM
function boldText(bt)
var name=prompt("","enter bold text");
document.form2.newstext.value=document.form2.newstext.value+" <b>"+name+"</b>";

12-17-2004, 08:31 PM
thanks for the quick reply..
and wow, so all i had to do was target the form name instead of just saying it was a form
thanks so much
does anyone know how to get cursor location and insert the text at that location..
or apply to highlited text


12-17-2004, 08:54 PM