PDA

View Full Version : my 'textarea script


skipion
10-31-2005, 06:15 PM
I've written this little javascript thingy to let people enter special tags within a textarea, I also implemented a character counter... all works well..though I would like to see the following points added:

- When a 'special tag' button is clicked a 'tag' is placed within the textarea, however the focus aint placed back into the textarea.

- When a text is pasted into the textarea, the character count only works if i scroll up or down, thats not a big issue as long the text is trimmed off when the form is submitted. So how do i trimm off the text on submition ?

- Does this code work on the major browsers ?

- I would like to build in a No javascript message, but havent got a clue on how to do that.

If anyone can help me with one or more of the issues above...thanks !!



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Untitled</title>
<script language="JavaScript" type="text/javascript">
<!--
vetchk = 0; cursiefchk=0; maxlimit=125;

function vet() {
if (vetchk==0) {
//document.getElementById("adam").style.fontWeight="bold";
Vetindex.value='*';
adam.value+='[B]';
vetchk=1;
}else{
Vetindex.value='[B]';
adam.value+='';
vetchk=0;}
}

function cursief() {
if (cursiefchk==0) {Cursiefindex.value='*'; adam.value+='[C]'; cursiefchk=1;
}else{
Cursiefindex.value='[C]'; adam.value+=''; cursiefchk=0;}
}

//-->
</script>


<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function textCounter(field, countfield) {
if (field.value.length > maxlimit)
field.value = field.value.substring(0, maxlimit);
else
countfield.value = maxlimit - field.value.length;
}
// End -->
</script>


</head>
<body>
<input type="button" name="Vetindex" Value="[B]" style="width: 30px" onClick="vet()">
<input type="button" name="Cursiefindex" Value="[C]" style="width: 30px" onClick="cursief()">
<br>

<textarea id="adam" name="adam" wrap=physical style="width: 600 px; height: 200px;" onKeyDown="textCounter(adam,remLen);" onKeyUp="textCounter(adam,remLen);" onMouseUp="textCounter(adam,remLen);" onmousedown="textCounter(adam,remLen);">
</textarea><br>
<input readonly type=text name=remLen size=3 maxlength=3 value="125"> characters left</font>
<input type="button" value="Submit">

</body>
</html>

vwphillips
10-31-2005, 07:15 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Untitled</title>
<script language="JavaScript" type="text/javascript">
<!--
var vetchk = 0;
var cursiefchk=0;
var maxlimit=125;

function vet() {
adamobj=document.getElementById("adam")
vindexobj=document.getElementById('Vetindex');
if (vetchk==0) {
vindexobj.value='[b]*';
adamobj.value+='[b]';
vetchk=1;
}
else {
vindexobj.value='';
adamobj.value+='';
vetchk=0;
}
adamobj.focus();
}

function cursief() {
adamobj=document.getElementById("adam")
cindex=document.getElementById("Cursiefindex")
if (cursiefchk==0){
cindex.value='*';
adamobj.value+='[C]';
cursiefchk=1;
}
else{
cindex.value='[C]'; adamobj.value+=''; cursiefchk=0;
}
adamobj.focus();
}

//-->
</script>


<SCRIPT LANGUAGE="JavaScript">
<!-- Begin

function textCounter(field, countfield) {
adamobj=document.getElementById("adam")
cindex=document.getElementById("remLen")
if (adamobj.value.length>maxlimit){
adamobj.value = adamobj.value.substring(0, maxlimit);
}
cindex.value=maxlimit-adamobj.value.length;
}

// End -->
</script>


</head>
<body>
<input type="button" id="Vetindex" name="Vetindex" Value="[b]" style="width: 30px" onClick="vet()">
<input type="button" id="Cursiefindex" name="Cursiefindex" Value="[C]" style="width: 30px" onClick="cursief()">
<br>

<textarea id="adam" name="adam" wrap=physical style="width: 600 px; height: 200px;"
onkeyup="textCounter(adam,remLen);"
onblur="textCounter(adam,remLen);"
>
</textarea><br>
<input readonly type=text id="remLen" name="remLen" size=3 maxlength=3 value="125"> characters left</font>
<input type="button" value="Submit">
<script> vic=0; </script>
<form name=Show id=Show style="position:absolute;visibility:visible;top:450px;left:0px;" >
<input size=10 name=Show1 >
<input size=10 name=Show2 >
<input size=10 name=Show3 >
<input size=10 name=Show4 >
<input size=10 name=Show5 >
<input size=10 name=Show6 >
</form>

</body>
</html>