Hi,

I`m writing a mod for a forum but I`m getting an error with a piece of Javascript which checks the length of text typed into a text area.

The error only happens in IE and not firefox/mozilla

This is the JS

<script type="text/javascript">
function check_length( l_max , textBox )
	{
		item = eval( "document.theForm." + textBox );
        if( !item )
    	{
    		return false;
    	}
    	if( l_max < item.value.length )
    	{
    		alert( "{ipb.lang['l_over']}" + l_max + " {ipb.lang['l_characters']}." );
    	}
    	if( l_max == item.value.length )
    	{
    		alert( "{ipb.lang['l_equal']}" + l_max + " {ipb.lang['l_characters']}." );
    	}
    	if( l_max > item.value.length )
    	{
    		alert( "{ipb.lang['max_is']}" + l_max + " {ipb.lang['l_characters']}. {ipb.lang['youve_used']}" + item.value.length + " {ipb.lang['l_characters']}." );
    	}
	}
</script>

Anyone see a problem with it?

Member Avatar for excprgmr

In case you haven't gotten a reply to your question, try using innerText instead of value when you are trying to get the length of a textarea. It works for me.

1000s of Free Javascripts

<html>
<head>
<script type="text/javascript">
function checkLength(_str,_len)
{
  var _slen=_str.toString().length;
  if(!_slen || _len=="")
    return false;
  else if(_len<_slen)
    alert( "{ipb.lang['l_over']}" + _len + " {ipb.lang['l_characters']}." );
  else if(_len==_slen)
    alert( "{ipb.lang['l_equal']}" + _len + " {ipb.lang['l_characters']}." );
  else
    alert( "{ipb.lang['max_is']}" + _len + " {ipb.lang['l_characters']}. {ipb.lang['youve_used']}" + _slen + " {ipb.lang['l_characters']}." );
}
</script>
</head>
<body>
<form name=f1>
String:<input type=text name=t1 value="abcdefghi"><BR>
Length:<input type=text name=t2 value="3"><BR>
<input type=button onclick="checkLength(this.form.t1.value,this.form.t2.value)" value="Check length">
</form>
</body>
</html>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.