problems prepopulating text fields

Discussion in 'HTML' started by brian.newman@wpafb.af.mil, May 3, 2006.

  1. Guest

    I've written code like the following
    <script language="javascript">
    function populateTextField(strWidget, strInitialData) {
    var elem = (document.getElementById) ?
    document.getElementById(strWidget) : ((document.all) ?
    document.all(strWidget) : null);
    if (elem) {
    elem.value = strInitialData;
    }
    }

    function initForm() {
    populateTextField ("txtDateOfRank", " - - ");
    }
    </script>
    <body onload="initForm();">
    <form NAME="frmAttendeeInfo" id="frmAttendeeInfo">
    <div id="divDateOfRank">
    <p>Date of Rank</p>
    <INPUT TYPE="text" NAME="txtDateOfRank" id="txtDateOfRank" SIZE="8"
    MAXLENGTH="8"> <!-- in form dd-mm-yy -->
    </div>
    </form>
    </body>

    The value is assigned to the text field correctly upon page load, but
    once the page is loaded, I can't change the value in the text field.
    Nothing happens. The javascript consol in Firefox doesn't report an
    error.
    It seems like once the value is assigned via a "value = " in html, it
    prevents any further changes to the text field. I'm having the same
    problem in IE. If this is the case, then I've got a problem with the
    html. Does anyone know what the fix is?
    , May 3, 2006
    #1
    1. Advertising

  2. Martin Jay Guest

    In message <>,
    "" <> writes
    >I've written code like the following
    ><script language="javascript">
    >function populateTextField(strWidget, strInitialData) {
    > var elem = (document.getElementById) ?
    >document.getElementById(strWidget) : ((document.all) ?
    >document.all(strWidget) : null);
    > if (elem) {
    > elem.value = strInitialData;
    > }
    >}
    >
    >function initForm() {
    > populateTextField ("txtDateOfRank", " - - ");
    >}
    ></script>
    ><body onload="initForm();">
    ><form NAME="frmAttendeeInfo" id="frmAttendeeInfo">
    > <div id="divDateOfRank">
    > <p>Date of Rank</p>
    > <INPUT TYPE="text" NAME="txtDateOfRank" id="txtDateOfRank" SIZE="8"
    >MAXLENGTH="8"> <!-- in form dd-mm-yy -->
    > </div>
    ></form>
    ></body>
    >
    >The value is assigned to the text field correctly upon page load, but
    >once the page is loaded, I can't change the value in the text field.
    >Nothing happens. The javascript consol in Firefox doesn't report an
    >error.
    >It seems like once the value is assigned via a "value = " in html, it
    >prevents any further changes to the text field. I'm having the same
    >problem in IE. If this is the case, then I've got a problem with the
    >html. Does anyone know what the fix is?


    Works okay here, but it seems like a lot of effort to go to.

    Perhaps the problem you're seeing is that the maxsize of the input box
    is 8 and you also populate it with 8 characters, so the only way to edit
    the input is to delete what's already in it.

    To get a date I'd simply use something like this:

    <form>
    <input name="day" type="text" >
    <select name="month">
    <option value="1">January</option>
    <option value="2">February</option>
    <!-- etc... -->
    </select>

    <input name="year" type="text">

    <input type="submit"
    </form>

    Perhaps you're trying to achieve something more complicated?
    --
    Martin Jay
    Martin Jay, May 3, 2006
    #2
    1. Advertising

  3. Guest

    I want a textbox which has " - - " in it. If the first character
    the user types in the text field is "1", then the text field will
    change to "1 - - ". If the first two characters the user types in
    the field are " 1", then the text field will change to " 1- - ". If
    the first three characters the user types are " 11", then the text
    field will change to " 1-1 - " and so forth.
    I'd like to stay away from select tags if possible in this case since,
    in my opinion, it takes more time for a user to use three drop down
    list (one for the year, one for the month, and one for the day) than it
    does for the user to type the six characters of text.
    , May 3, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. call_me_anything
    Replies:
    4
    Views:
    459
    Pete Becker
    Sep 30, 2007
  2. Cyril.Liu
    Replies:
    0
    Views:
    444
    Cyril.Liu
    Dec 2, 2008
  3. middletree

    how to copy from fields to other fields

    middletree, Nov 5, 2003, in forum: ASP General
    Replies:
    1
    Views:
    158
    middletree
    Nov 5, 2003
  4. Replies:
    0
    Views:
    279
  5. AMT2K5
    Replies:
    1
    Views:
    191
    Eric Schwartz
    Nov 8, 2005
Loading...

Share This Page