Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

HTML Forum


You are currently viewing our HTML Forum as a guest. Please register to participate.
Login



Post a Project »

Find a Professional HTML Freelancer!

Find a Freelancer to help you with your HTML projects

FREE Outsourcing eBook!

Reply
setting focus to dynamically built text box
Old 09-05-2006, 03:19 PM setting focus to dynamically built text box
Junior Talker

Posts: 1
Name: Rosanne
Trades: 0
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&nbsp;[RowLabel]:&nbsp;&nbsp;<INPUT id=""txtAddItemColumn"" type=""text"" size=""50"" name=""txtAddItemColumn"" onblur=""txtAddItemColumn_OnChange"" MaxLength=""35"">&nbsp;&nbsp;<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&nbsp;[RowLabel]:<INPUT id=""txtAddItemColumn"" type=""text"" size=""50"" name=""txtAddItemColumn"" onblur=""txtAddItemColumn_OnChange"" MaxLength=""35"">&nbsp;&nbsp;<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!
Rosanne is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Reply     « Reply to setting focus to dynamically built text box
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.09246 seconds with 12 queries