By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,970 Members | 1,669 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,970 IT Pros & Developers. It's quick & easy.

Form counter & prefilled form field

P: n/a
Hi,

Having an issue with a pretty standard javascript text counter. The
counter works fine when a user physically enters text into a textbox
but shoudl the textbox have a value prefilled then the prefilled value
is not taken into account until the user has entered something in the
textbox.

So basically I have a textbox with "hello" in it and a text counter
which say "10" it is not until the user clicks on the textbox and then
presses key or chnages the text that the counter updates and takes the
"hello" into account, thus chanign the textcounter value to 4 as the
user woudl have pressed the spacebar in this example.

Hope this makes sense. has anyone got any idea on how I can get around
this?
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Ben Barnes wrote:
Hi,

Having an issue with a pretty standard javascript text counter. The
counter works fine when a user physically enters text into a textbox
but shoudl the textbox have a value prefilled then the prefilled value is not taken into account until the user has entered something in the
textbox.

So basically I have a textbox with "hello" in it and a text counter
which say "10" it is not until the user clicks on the textbox and then presses key or chnages the text that the counter updates and takes the "hello" into account, thus chanign the textcounter value to 4 as the
user woudl have pressed the spacebar in this example.

Hope this makes sense. has anyone got any idea on how I can get around this?


Hi Ben.

Where is the 'prefilled' text coming from? If it's being printed at the
server, the same routine could also initialize the counter. Otherwise,
you can always set an onload handler for the page that explicitly calls
the HTML event handler property involved, e.g.

<input id="foo"....onchange="textcount(this)" />

....can be called:

window.onload = function()
{
document.getElementById('foo').onchange();
}

Jul 23 '05 #2

P: n/a

RobB wrote:
Ben Barnes wrote:
Hi,

Having an issue with a pretty standard javascript text counter. The
counter works fine when a user physically enters text into a textbox but shoudl the textbox have a value prefilled then the prefilled value
is not taken into account until the user has entered something in the textbox.

So basically I have a textbox with "hello" in it and a text counter
which say "10" it is not until the user clicks on the textbox and

then
presses key or chnages the text that the counter updates and takes

the
"hello" into account, thus chanign the textcounter value to 4 as the user woudl have pressed the spacebar in this example.

Hope this makes sense. has anyone got any idea on how I can get

around
this?


Hi Ben.

Where is the 'prefilled' text coming from? If it's being printed at

the server, the same routine could also initialize the counter. Otherwise, you can always set an onload handler for the page that explicitly calls the HTML event handler property involved, e.g.

<input id="foo"....onchange="textcount(this)" />

...can be called:

window.onload = function()
{
document.getElementById('foo').onchange();
}

Hi,

Thanks for taking the time to write.

The text has a value set dynamically from a users input. The problem is
this can change to any length but the counter has a set value which
does not take into accoutn what he user has entered.
I'll give what you have suggested a shot.

Thanks

Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.