|
We needed a way to give the users an unlimited amount of text boxes in which to enter values. At run time we have no idea how many values they have to enter. So, I am building a dynamic string and displaying that on the page. The user can enter the value and click the <More> button to get another row in which to enter a value.
Here are the details:
In vbscript I am building a dynamic string:
strColumn = "<div id=""lblColumns[RowID]"" style=""display:inline;"">Column [RowLabel]: <INPUT id=""txtAddItemColumn"" type=""text"" size=""50"" name=""txtAddItemColumn"" onblur=""txtAddItemColumn_OnChange"" MaxLength=""35""> <INPUT id=""btnRow"" onclick=""AddNewColumn()"" type=""button"" WIDTH: 7px; value=""More""></div><BR>"
The variables in the dynamic string [RowID] and [RowLabel] are replaced with a counter:
strTemp1 = replace(strColumn,"[RowID]",cstr(intColumnCount))
strTemp2 = replace(strTemp1,"[RowLabel]",cstr(intColumnCount + 1))
This string is put into a label on the page:
lblAddColumns.innerHTML = strTemp1 + strTemp2
Basically what this does it builds a string that contains a label (lblColumns(n)), text box (txtAddItemColumn) and button (btnRow) and displays it to the page:
Row 1: [ text box here ] <More>
The user can enter text (or leave the box blank) then hit the <More> button, to add another row. When they click the <More> button, the following method is called:
Sub AddNewColumn()
dim strTemp1, strTemp2
intColumnCount = intColumnCount + 1
'when intColumnCount = 9 we are actually writing out the 10th row...it's a 0-based array
if intColumnCount > 8 then
strColumn = "<div id=""lblColumns[RowID]"" style=""display:inline;"">Column [RowLabel]:<INPUT id=""txtAddItemColumn"" type=""text"" size=""50"" name=""txtAddItemColumn"" onblur=""txtAddItemColumn_OnChange"" MaxLength=""35""> <INPUT id=""btnRow"" onclick=""AddNewColumn()"" type=""button"" WIDTH: 7px; value=""More""></div><BR>"
endif
strTemp1 = replace(strColumn,"[RowID]",cstr(intColumnCount))
strTemp2 = replace(strTemp1,"[RowLabel]",cstr(intColumnCount + 1))
lblAddColumns.innerHTML = lblAddColumns.innerHTML + strTemp2
'works properly. If I remove the message boxes, the focus line doesn't work.....
'msgbox intColumnCount
'msgbox document.getElementsByName("txtAddItemColumn").ite m(intColumnCount).value
document.getElementsByName("txtAddItemColumn").ite m(intColumnCount).focus
EndSub
The more button just concatenates another row onto the string and places the new string in the label on the page. All of this is working fine. Here's the problem - in the AddNewColumn method, I need to set the focus on the NEW text box that was just added (you can see that in the last line of the method. However, it's not working. If I add 2 message boxes to the method just before the focus line (you can see the commented out msgbox lines in the code above), the focus is set properly. If I remove the message boxes, the focus does not get set.
Does this make any sense? It's been driving me nuts! Any ideas/suggestions will be so, so appreciated!!!!
Thanks in advance!
|