472,961 Members | 1,518 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,961 software developers and data experts.

srcElement and innerText and?

To show users how many characters they have left in a TEXTAREA input I
have been using "taCount" from a website I googled.

function taCount(visCnt) {
var taObj=event.srcElement;
if (taObj.value.length>taObj.maxLength*1)
taObj.value=taObj.value.substring(0,taObj.maxLengt h*1);
if (visCnt) visCnt.innerText=taObj.value.length;
}

After googling I found out that firefox does not allow
"event.srcElement" and "innerText" to work so I tried substituting
with

var taObj = (event.target) ? event.target : event.srcElement
innerText to innerHTML

But it is still not working.

Entire code..

<script language="JavaScript" type="text/javascript">

function taLimit(taObj) {
var taObj = (event.target) ? event.target : event.srcElement
if (taObj.value.length==taObj.maxLength*1) return false;
}

function taCount(taObj, visCnt) {
var taObj = (event.target) ? event.target : event.srcElement
if (taObj.value.length>taObj.maxLength*1)
taObj.value=taObj.value.substring(0,taObj.maxLengt h*1);
if (visCnt) visCnt.innerHTML=taObj.maxLength-taObj.value.length;
}

</script>

You have <B>
<div id="txtmsg" class="scfmfrm_dept">&nbsp;</div>

<span id="myCounter">255</SPAN></Bcharacters remaining
for your description..

<TEXTAREA onkeypress="taLimit(this)" onkeyup="return taCount(this,
myCounter)"
name=Description rows=7 wrap=physical cols=40 maxLength="255"></
TEXTAREA>

Anyone know what other problems firefox is having with this?

Garry Jones
Sweden
Sep 6 '08 #1
5 3369
GarryJones wrote:
<TEXTAREA onkeypress="taLimit(this)" onkeyup="return taCount(this,
myCounter)"
name=Description rows=7 wrap=physical cols=40 maxLength="255"></
TEXTAREA>

Anyone know what other problems firefox is having with this?
There is no maxlength attribute defined for 'textarea' elements. see
http://www.w3.org/TR/html4/interact/forms.html#h-17.7
Consequently the DOM does not define a maxLength property, see
http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-24874179
That way your code
taObj.maxLength
gives undefined with Firefox.
Try
taObj.getAttribute("maxlength")
instead or (for IE I fear)
taObj.getAttribute("maxLength")

--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 6 '08 #2
On Sep 6, 11:30*am, GarryJones <mor...@algonet.sewrote:
To show users how many characters they have left in a TEXTAREA input I
have been using "taCount" from a website I googled.

function taCount(visCnt) {
var taObj=event.srcElement;
if (taObj.value.length>taObj.maxLength*1)
taObj.value=taObj.value.substring(0,taObj.maxLengt h*1);
if (visCnt) visCnt.innerText=taObj.value.length;

}

After googling I found out that firefox does not allow
"event.srcElement" and "innerText" to work so I tried substituting
with

var taObj = (event.target) ? event.target : event.srcElement
innerText to innerHTML

But it is still not working.

Entire code..

<script language="JavaScript" type="text/javascript">

function taLimit(taObj) {
var taObj = (event.target) ? event.target : event.srcElement
*if (taObj.value.length==taObj.maxLength*1) return false;

}

function taCount(taObj, visCnt) {
var taObj = (event.target) ? event.target : event.srcElement
*if (taObj.value.length>taObj.maxLength*1)
taObj.value=taObj.value.substring(0,taObj.maxLengt h*1);
*if (visCnt) visCnt.innerHTML=taObj.maxLength-taObj.value.length;

}

</script>

You have <B>
<div id="txtmsg" class="scfmfrm_dept">&nbsp;</div>

<span id="myCounter">255</SPAN></Bcharacters remaining
for your description..

<TEXTAREA onkeypress="taLimit(this)" onkeyup="return taCount(this,
myCounter)"
name=Description rows=7 wrap=physical cols=40 maxLength="255"></
TEXTAREA>

Anyone know what other problems firefox is having with this?

Garry Jones
Sweden
Give this a crack, it's only simple but it works in IE, FF and chrome.

<html>
<head>
<script>
function showLimit(src, limit, displayElem)
{
var srcElem = document.getElementById(src);
var displayElem =
document.getElementById(displayElem);
var strText= srcElem.value;
var intLen = strText.length;
var intRemaining = limit - intLen;

if (intRemaining <= 0)
{
var newVal = srcElem.value.substr(0, limit);
srcElem.value = newVal;
displayElem.innerHTML = 0;
return;
}
displayElem.innerHTML = intRemaining;
}
</script>
</head>
<body>
You have <b><span id="numLeft">10</span></bcharacters
remaining<br>
<textarea id="ta" onkeyup="showLimit('ta', 10, 'numLeft');"></
textarea>
</body>
</html>
Sep 6 '08 #3
Garry,

- In IE, event is a global object. In firefox, you have to get it
through the event handler. Firefox passes event object as the first
param to the event handler.
- maxLength attribute is valid for INPUT fields, but not valid for
TEXTAREA
- To access 'myCounter' span, get the reference using
document.getElementById

I have made the above mentioned changes, this is the modified code:
--------
<script language="JavaScript" type="text/javascript">

function taLimit(event, taObj, maxLength) {
var taObj = (event.target) ? event.target : event.srcElement
if (taObj.value.length==maxLength) return false;
}

function taCount(event, taObj, maxLength, visCnt) {
var taObj = (event.target) ? event.target : event.srcElement

if (taObj.value.length>taObj.maxLength)
taObj.value=taObj.value.substring(0,maxLength);

if (visCnt) visCnt.innerHTML=maxLength-taObj.value.length;
}

</script>

You have <B>
<div id="txtmsg" class="scfmfrm_dept">&nbsp;</div>

<span id="myCounter">255</SPAN></Bcharacters remaining
for your description..

<TEXTAREA onkeypress="taLimit(event, this, 255)"
onkeyup="return taCount(event, this, 255,
document.getElementById('myCounter'))"
name=Description rows=7 wrap=physical cols=40></TEXTAREA>
--------

Kiran Makam

Sep 6 '08 #4
SAM
GarryJones a écrit :
To show users how many characters they have left in a TEXTAREA input I
have been using "taCount" from a website I googled.
<script type="text/javascript">
function leftText(where, max) {
if(!where.repport) {
where.repport = document.createElement('P');
where.parentNode.insertBefore(where.repport, where);
}
where.repport.className = '';
var t = where.value;
var q = max - t.length;
where.repport.innerHTML = q>0? 'Characters remaining : '+q :
q==0? 'Filled up !' : 'Filling back';
if(q<0) {
where.value = t.substring(0,t.length-1);
where.repport.className = 'red';
}
}

</script>

<style type="text/css">
..red { color: red; font-weight: bold }
</style>

<form>
<textarea onkeyup="leftText(this, 25);">test</textarea>
<textarea onkeyup="leftText(this, 15);">test</textarea>
</form>

--
sm
Sep 6 '08 #5
On Sep 6, 1:58*pm, SAM <stephanemoriaux.NoAd...@wanadoo.fr.invalid>
wrote:
GarryJones a écrit :
To show users how many characters they have left in a TEXTAREA input I
have been using "taCount" from a website I googled.

<script type="text/javascript">
function leftText(where, max) {
if(!where.repport) {
* *where.repport = document.createElement('P');
* *where.parentNode.insertBefore(where.repport, where);
* *}
where.repport.className = '';
var t = where.value;
var q = max - t.length;
where.repport.innerHTML = q>0? 'Characters remaining : '+q :
* * * * q==0? 'Filled up !' : 'Filling back';
if(q<0) {
* *where.value = t.substring(0,t.length-1);
* *where.repport.className = 'red';
* *}

}

</script>

<style type="text/css">
.red { color: red; font-weight: bold }
</style>

<form>
<textarea onkeyup="leftText(this, 25);">test</textarea>
<textarea onkeyup="leftText(this, 15);">test</textarea>
</form>

--
sm
Yeah, Sam's is better... use his :)
Sep 6 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Dan | last post by:
Hi, When i click down with the mouse, i want to be sure that the image "myimg" is clicked before doing something. With IE i use 'srcElement' and it works: <IMG ID="myimg" SRC="bugs.gif"...
5
by: Jeff Thies | last post by:
I have this IE specific bit of code for finding the originating node: var obj=window.event.srcElement; How do I do that cross browser (Opera, NS, Safari...)? Is there a standard DOM method? ...
6
by: martin | last post by:
Hi, I would like to write the text of an element to an xml doc as that it look like this <Address>&quot;Marty Jones&quot; &lt;mj@mydomain.com&gt;</Address> however I can't seen to get the quote marks to...
13
by: Lyners | last post by:
I have a web page writen in ASP.NET that contains some javascript so that when a user presses a button, or edits a certain field in a datagrid, another cell in the datagrid is filled with a value....
10
by: Angel | last post by:
I want to concat a space in an HTML Control's innerText property. here is a sample code Dim celCreate As New HtmlControls.HtmlTableCell() celCreate.innerText = " TEST" When the page is...
4
by: Josselin | last post by:
I am loading a group of items (urls of images to load) group.items for each items I associate the filename and an <img> object on my page using : .... var pair = new ImagePair(group.items);...
9
by: stevewy | last post by:
I am trying to write a function that will test all the checkboxes in a particular group of a form (it's a questionnaire), see whether more than three of them are ticked, and display a message if...
3
by: Jake G | last post by:
Ok. I have figured out my whole script except how to make it work in FF. It is a script that lets a user know how many characters they have left for a textbox. Here is the code, is anyone savy...
5
by: anEchteTrilingue | last post by:
Hi everybody. Thank you for reading my post. I am having trouble getting "this" to work in all versions of IE (it's fine in Firefox, opera, konqueror, etc). What I would like to do is add an...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.