|
|
|||||||||
|
|||||||||
|
|||||||||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
Javascipt: counting chars!
I have amended a javascript function i found on the web to count charecters within a textbox as i write in it. This works...
Code = Code:
<html>
<head>
<title></title>
<script type="text/javascript" >
function CheckFieldLength(fn,wn,rn,mc) {
var len = fn.value.length;
if (len > mc) {
fn.value = fn.value.substring(0,mc);
len = mc;
}
document.getElementById(wn).innerHTML = len;
}
</script>
</head>
<body bgcolor="#ffffff" >
<form name=form1 method=post action='http://www.plus2net.com'>
<textarea name="product_profile" cols="120" rows="15" class="formelement" id="taMessage" onkeyup="CheckFieldLength(taMessage, 'charcount', 'remaining', 10000);" onkeydown="CheckFieldLength(taMessage, 'charcount', 'remaining', 10000);" onmouseout="CheckFieldLength(taMessage, 'charcount', 'remaining', 10000);"></textarea>
<strong>Contains <span id="charcount" class="compulsory">0</span> characters entered. </strong></p>
</form>
</body>
</html>
The problem i have is i don't want this counter to include spaces. Thanks in advance Can anyone help? |
|
#2
|
|||
|
|||
|
answe
Code:
r
<html>
<head>
<title></title>
<script type="text/javascript" >
function CheckFieldLength(fn,wn,rn,mc) {
var len = fn.value.length;
if (len > mc) {
fn.value = fn.value.substring(0,mc);
len = mc;
}
var spaces = 0
//window.alert(document.getElementById('taMessage'). value.split(' ').length )
if (document.getElementById('taMessage').value.split( ' ').length > 1 )
{
spaces = document.getElementById('taMessage').value.split(' ').length;
spaces = spaces - 1
}
else
{
spaces = 0
}
document.getElementById(wn).innerHTML = len - spaces;
//window.alert(len)
}
</script>
</head>
<body bgcolor="#ffffff" >
<form name="form1" method=post action='http://www.plus2net.com'>
<textarea name="product_profile" cols="120" rows="15" class="formelement" id="taMessage" onkeyup="CheckFieldLength(taMessage, 'charcount', 'remaining', 10000);" onkeydown="CheckFieldLength(taMessage, 'charcount', 'remaining', 10000);" onmouseout="CheckFieldLength(taMessage, 'charcount', 'remaining', 10000);"></textarea>
<strong>Contains <span id="charcount" class="compulsory">0</span> characters entered. </strong></p>
</form>
</body>
</html>
|
![]() |
| Viewing: ASP Free Forums > Programming > HTML, JavaScript And CSS Help > Javascipt: counting chars! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|
|