/    Sign up×
Community /Pin to ProfileBookmark

multiline textbox validation behaves differently in IE and FF

hi all , i want that user can not enter text in multiline textbox more than specific characters but it behaves differently in IE and FF. In Internet explorer when i press enter key it takes two character whereas in firefox when i press enter it takes only one character. so this way user can enter more data in FF which is not correct. how to fix that behavior so that both browsers give same result. My javascript code is given below

<HTML>
<HEAD>
<TITLE> Javascript Character Count by WebSewak.com </TITLE>
<script language=”Javascript”>
function counterUpdate(opt_countedTextBox, opt_countBody, opt_maxSize) {
var countedTextBox = opt_countedTextBox ? opt_countedTextBox : “counttxt”;
var countBody = opt_countBody ? opt_countBody : “countBody”;
var maxSize = opt_maxSize ? opt_maxSize : 1024;

var field = document.getElementById(countedTextBox);

if (field && field.value.length >= maxSize) {
field.value = field.value.substring(0, maxSize);
}
var txtField = document.getElementById(countBody);
if (txtField) {
txtField.innerHTML = field.value.length;
}

}
</script>
</HEAD>

<BODY>
<textarea id=”counttxt” name=”counttxt” rows=”10″ onkeyup=”counterUpdate(‘counttxt’, ‘countBody’,’30’);”></textarea>

You typed <B><span id=”countBody”>0</span></b> characters
Max. Length : 30 Chars
</BODY>
</HTML>

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@FangMay 12.2009 — &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
&lt;HTML&gt;
&lt;HEAD&gt;
&lt;TITLE&gt; Javascript Character Count by WebSewak.com &lt;/TITLE&gt;
&lt;script language="Javascript"&gt;
function counterUpdate(opt_countedTextBox, opt_countBody, opt_maxSize) {
var countedTextBox = opt_countedTextBox ? opt_countedTextBox : "counttxt";
var countBody = opt_countBody ? opt_countBody : "countBody";
var maxSize = opt_maxSize ? opt_maxSize : 1024;

var field = document.getElementById(countedTextBox);

if (field &amp;&amp; field.value.length &gt;= maxSize) {
field.value = field.value.substring(0, maxSize);
}
[COLOR="Blue"]var str = field.value.replace(/r/g,'');[/COLOR]
var txtField = document.getElementById(countBody);
if (txtField) {
txtField.innerHTML = field.value.length+":"+[COLOR="Blue"]str.length[/COLOR];
}
}
&lt;/script&gt;
&lt;/HEAD&gt;

&lt;BODY&gt;
&lt;textarea id="counttxt" name="counttxt" rows="10" onkeyup="counterUpdate('counttxt', 'countBody','30');"&gt;&lt;/textarea&gt;

You typed &lt;B&gt;&lt;span id="countBody"&gt;0&lt;/span&gt;&lt;/b&gt; characters
Max. Length : 30 Chars
&lt;/BODY&gt;
&lt;/HTML&gt;
×

Success!

Help @write2atif spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...