Forum Moderators: open
Thanks!
If yes, then it can be done through JavaScripts :) Below is the code
### Code between <head> </head>
<script language = "Javascript">
function taLimit() {
var taObj=event.srcElement;
if (taObj.value.length==taObj.maxLength*1) return false;
}
function taCount(visCnt) {
var taObj=event.srcElement;
if (taObj.value.length>taObj.maxLength*1) taObj.value=taObj.value.substring(0,taObj.maxLength*1);
if (visCnt) visCnt.innerText=taObj.maxLength-taObj.value.length;
}
</script>
#######
<textarea rows="7" name="TEXTAREA-NAME" onkeypress="return taLimit()" onkeyup="return taCount(myCounter)" maxLength="2000" cols="38"></textarea><br>
<font size="2" face="Arial">You have <font color="#CC0000"> <B><SPAN id=myCounter>
2000</SPAN></B></font> characters remaining ...</font> </font>
##############
I am sure you got the drill, on how it works. Also, you can use same <head> code for multiple use within the same page.
There might be some better ways out there, but I am only aware of this one. :(
Hope this helps :)
If you put up something browser specific, just make sure it isn't mission critical.
Have heard rumors that the recent betas of ie even allow users to set their own font size in form elements.
Why not? For example, this:
.one4all { font: 8pt verdana,arial,sans-serif; color: gold; width: 100px }
applied to different form elements like <input type=text>, <textarea> or <select> will set their text and width exactly the same in Opera, IE and Mozilla on Win (I can't test on other OS like Mac, for example). The only exception is that Opera will not change the text color.
In order to make width of an element look the same in NN4, you have to use a combination of font settings in CSS and "size" attribute of an <input> tag (or "cols" attribute of <textarea>) - just play with it a little and you'll get it looking almost or exactly the same as in other browsers.
NeedsScripts
Thanks, wonderful script. I actually found one similar to this on Dynamic Drive web site. My question is now can I get this script to function in Netscape Navigator 4.x and IE4? I realize this type of script works fine in the latest browsers but my user base unfortunately is behind the times. Here's the code I used...
<SCRIPT TYPE="text/javascript">
/*
Form field Limiter script- By Dynamic Drive
For full source code and more DHTML scripts, visit [dynamicdrive.com...]
This credit MUST stay intact for use
*/
var ns6=document.getElementById&&!document.all
function restrictinput(maxlength,e,placeholder){
if (window.event&&event.srcElement.value.length>=maxlength)
return false
else if (e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength){
var pressedkey=/[a-zA-Z0-9\.\,\/]/ //detect alphanumeric keys
if (pressedkey.test(String.fromCharCode(e.which)))
e.stopPropagation()
}
}
function countlimit(maxlength,e,placeholder){
var theform=eval(placeholder)
var lengthleft=maxlength-theform.value.length
var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder)
if (window.event¦¦e.target&&e.target==eval(placeholder)){
if (lengthleft<0)
theform.value=theform.value.substring(0,maxlength)
placeholderobj.innerHTML=lengthleft
}
}
function displaylimit(theform,thelimit){
var limit_text='<b><span id="'+theform.toString()+'">'+thelimit+'</span></b> characters remaining on your input limit'
if (document.all¦¦ns6)
document.write(limit_text)
if (document.all){
eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)}
eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}
}
else if (ns6){
document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true);
document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true);
}
}
</SCRIPT>
And the script to put along with the form element...
<SCRIPT>displaylimit("document.form.szComments",255)</SCRIPT>
About CSS, I think if you are using TopStyle [I love it, it is very good and I would say best css editor ever made], it will tell you if your CSS will work with Netscape 4 or other browers or not.
One line of CSS will solve my problem.. geez man what is it :-)?? I'll see if I can find it in the CSS 2 Specifications.
I was just initially worried about using CSS because I figured it wouldn't work in Netscape 4.x.