Requesting value form a dynamic text box

Hello people,

Can anybody assist on how I can request the values thats is inputed into a dynamic textbox (That is, a text box that is repeating itself based on the number of rows returned in a recordset)

I hope to hear from you all very soon.

Thank you.
babsjidAsked:
Who is Participating?
 
mellaConnect With a Mentor Commented:
Dear babsjid,

if I understand you right, you have problems with requesting what was put into an unknown number of text fields.

You might want to create your dynamic textfields with the same name for all of them, e. g. "mytextfield". Then, when you request your form inputs on the form processing asp page, when you request "mytextfield" you will get the values of all your dynamic textfields as one string, separated by commas. You split them up into an array, and loop through the array in order to access each of them separately. See the code below. Hope to have helped.

-------------------------------
Code for myform.asp

<%
sql="select myfield1, myfield2, myfield3 from mytable"
rs.open sql, objconn
%>


<form name="myform" method="Post" action="form_processing.asp" >

<%do while not rs.eof
%>

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

<%
rs.movenext
loop
%>

</form>
<%rs.close%>

-------------------------------
Code for form_processing.asp

<%
'request the textfield from the previous page
'what you will get is the values of your dynamic textfields all in one string, separated by commas

mytextfield=Request.form("mytextfield")

'to separate the values, split them up into a string

myarray=split(mytextfield, ",")

'now you have an array which contains the values of your dynamic textfields. To access them separately, and add them, for example, to a database, you can loop through the array

for i=0 to ubound(myarray)
 sql="Select myfield from mytable"
 rs.open sql, objconn, 3,3
 rs.addnew
 if trim(myarray(i))<>"" then
   RS("myfield")=myarray(i)
 end if
 rs.update
 rs.close
next
%>
0
 
hongjunCommented:
>>how I can request the values
Client side? How do you name the dynamic textboxes? If it is something like thi

<form name="frmMain">
<%
do while not rs.eof
%>
    <input type="text" name="mytext"...>
<%
loop
%>
</form>


Since you are having more than 1 textboxes having the same name "mytext", you can actually use the below to get the values.


<script language="JavaScript">
alert(document.frmMain.mytext[0].value);  // get first textbox
alert(document.frmMain.mytext[1].value);  // get second textbox
</script>


hongjun
0
 
Sashi RachabattulaSCRUM Master, .NET Project LeadCommented:
pls send yhe code of ur Creation od dynamic text box
0
 
GaryCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept Answer by mella

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
GaryC123
EE Cleanup Volunteer
0
All Courses

From novice to tech pro — start learning today.