Form counter & prefilled form field

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ben Barnes

    #1

    Form counter & prefilled form field

    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?
  • RobB

    #2
    Re: Form counter & prefilled form field

    Ben Barnes wrote:[color=blue]
    > 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[/color]
    value[color=blue]
    > 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[/color]
    then[color=blue]
    > presses key or chnages the text that the counter updates and takes[/color]
    the[color=blue]
    > "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[/color]
    around[color=blue]
    > this?[/color]

    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"....onc hange="textcoun t(this)" />

    ....can be called:

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

    Comment

    • benbarnes007@hotmail.com

      #3
      Re: Form counter &amp; prefilled form field


      RobB wrote:[color=blue]
      > Ben Barnes wrote:[color=green]
      > > Hi,
      > >
      > > Having an issue with a pretty standard javascript text counter. The
      > > counter works fine when a user physically enters text into a[/color][/color]
      textbox[color=blue][color=green]
      > > but shoudl the textbox have a value prefilled then the prefilled[/color]
      > value[color=green]
      > > is not taken into account until the user has entered something in[/color][/color]
      the[color=blue][color=green]
      > > 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[/color]
      > then[color=green]
      > > presses key or chnages the text that the counter updates and takes[/color]
      > the[color=green]
      > > "hello" into account, thus chanign the textcounter value to 4 as[/color][/color]
      the[color=blue][color=green]
      > > user woudl have pressed the spacebar in this example.
      > >
      > > Hope this makes sense. has anyone got any idea on how I can get[/color]
      > around[color=green]
      > > this?[/color]
      >
      > Hi Ben.
      >
      > Where is the 'prefilled' text coming from? If it's being printed at[/color]
      the[color=blue]
      > server, the same routine could also initialize the counter.[/color]
      Otherwise,[color=blue]
      > you can always set an onload handler for the page that explicitly[/color]
      calls[color=blue]
      > the HTML event handler property involved, e.g.
      >
      > <input id="foo"....onc hange="textcoun t(this)" />
      >
      > ...can be called:
      >
      > window.onload = function()
      > {
      > document.getEle mentById('foo') .onchange();
      > }[/color]


      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

      Comment

      Working...