Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > problems prepopulating text fields

Reply
Thread Tools

problems prepopulating text fields

 
 
brian.newman@wpafb.af.mil
Guest
Posts: n/a
 
      05-03-2006
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?

 
Reply With Quote
 
 
 
 
Martin Jay
Guest
Posts: n/a
 
      05-03-2006
In message < .com>,
"" <> 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
 
Reply With Quote
 
 
 
 
brian.newman@wpafb.af.mil
Guest
Posts: n/a
 
      05-03-2006
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
epydoc: How to add new fields as the building fields? Cyril.Liu Python 0 12-02-2008 05:01 AM
print struct fields and its member structs' fields recursively, generically call_me_anything C++ 4 09-30-2007 10:12 PM
Newbie - Reading a file with delimited fields, storing first two fields in a hash AMT2K5 Perl Misc 1 11-08-2005 01:06 AM
how to copy from fields to other fields middletree ASP General 1 11-05-2003 06:24 PM
Netscape hidden fields - array - multiple fields with same name mark.reichman@rl.af.mil Javascript 0 07-17-2003 03:05 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57