User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 402,049 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,554 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 3914 | Replies: 2
Reply
Join Date: Nov 2004
Posts: 1
Reputation: MMX is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
MMX MMX is offline Offline
Newbie Poster

Javascript help please

  #1  
Nov 16th, 2004
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?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2004
Location: Garland, Texas
Posts: 1
Reputation: excprgmr is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
excprgmr excprgmr is offline Offline
Newbie Poster

Re: Javascript help please

  #2  
Nov 23rd, 2004
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.
Reply With Quote  
Join Date: Nov 2004
Location: Dallas, TX [USA]
Posts: 9
Reputation: js-x.com is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
js-x.com js-x.com is offline Offline
Newbie Poster

Re: Javascript help please

  #3  
Nov 24th, 2004
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>
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 11:42 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC