Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

insert the contents of dynamically generated textbox in a table. 2

Status
Not open for further replies.

GoldPearl

Programmer
Joined
Aug 9, 2005
Messages
64
(asp 3.0 + sql server 2K)

i want to insert the contents of dynamically generated textbox in a table.

in my first web page, a user can make a series of selection (eg select a position - let's say 'engineer').

when the user clicks the next button(next1), a table is displayed with the employeeid, duty and a blank textbox where the user can input the scores.(same format as below: user-duty-score)

after filling in the scores, the user clicks the next button(next2) to input the data in the database, but the insert statement is not doing what i want it to do. it is inserting the scores on the same line as 2,3(eg of scores) and i want it to display separately in the table as:

user1 duty1 score1
user1 duty2 score2
user1 duty3 score3
etc...

enclosed is the code for the next2 button:

Sub Next2
dim rs
dim cn
Dim sql, sql1
dim i

date1=request.form("txtdate")
per=request.form("lstper")
emp=request.form("lstemp")
pos=request.form("lstpos")
dept=request.form("lstdept")
pjt=request.form("lstpjt")
response.Write(emp)
Set cn = Server.CreateObject("ADODB.Connection")
cn.Open(Conn)

Set rs = Server.CreateObject("ADODB.Recordset")

txtmscore = request.Form("txtmscore")
'for i = 0 to txtmscore
sql = "INSERT INTO mdutyscore (userid, mdscore) VALUES ('" & request.Form("lstemp") & "' ,'" & txtmscore & "' )"
'response.Write(sql)
'response.End()

cn.Execute(sql)
'next

end sub


anybody can help me out. it's urgent.
Tks
Gold Pearl.
 
Write out your UserID & Scores Arrays see what they look like.
 
when i write out the userid, i get this error:

Error Type:
Microsoft VBScript runtime (0x800A0009)
Subscript out of range: ''


the score works fine.
 
Let's try this:

Code:
txtmscore = request.Form("txtmscore")
score = split(txtmscore,", ")

txtUID = request.Form("lstemp")
uid = split(txtUID,", ")

response.write("txtUID")
response.write("txtmscore")
response.end()

for i = 0 to UBound(score)-1
sql = "INSERT INTO mdutyscore (userid, mdscore) VALUES ('" & uid(i) & "' ,'" & score(i) & "' )"
response.Write(sql)
cn.Execute(sql)
next
 
oops ...

response.write(txtUID)
response.write(txtmscore)
response.end()
 
displays only the scores :(

for each duty, it does display the userid and an empty textbox to enter the scores. dunno y it is not taking the value on the next2 button sybmit.
 
that means your txtUID empty...track it down and see where its getting empty...

-DNG
 
it's in this code i've sent u that there is an error. because in my first page, it retrieves the id of the employee and displays it in the 2nd page in the format:

userid duty1 score1
userid duty2 score2
userid duty3 score3
etc

the userid is being displayed correctly but when now am trying to retrieve the userid from the firstpage, it doesn't do so.

well these are the only 2 places userid is referred to.
what more can i do? :(

can't i retrieve the userid where the score is being retrieved (table above)?

Gold Pearl.

 
code for the table generated dynamically is as follows:


<table width="52%" border="2" cellpadding="4" bordercolor="#CCCCCC" bgcolor="#CCCCCC" nowrap>
<tr bordercolor="#CCCCCC">
<!-- Table headers: -->
<td width="40%" align="center"><strong><font color="#000000" size="2" face="Arial">Employee
ID</font></strong></td>
<td width="51%" align="center"><strong><font color="#000000" size="2" face="Arial">Duty</font></strong></td>
<td width="9%" align="center"><strong><font color="#000000" size="2" face="Arial">Score</font></strong></td>
</tr>
<%
' Now, create the INPUT Boxes that make up our
' "DataSheet" and populate them
Do Until rs.EOF
%>
<tr bordercolor="#CCCCCC">
<td><div align="center"><font color="#000000" size="2" face="Arial"><%=emp%></font></div></td>
<td><div align="left"><font color="#000000" size="2" face="Arial"><%=rs("duty")%></font></div></td>
<td> <div align="center">
<input name="txtmscore" type="text" id="txtmscore" size="5">
</div></td>
</tr>
<%
rs.MoveNext
loop
end if
%>
</table>


 
hello....

where is everybody gone?
noone willing to help me out anymore?
 
You don't have a textbox name "lstemp" in your table. That's why when you try to retrieve its value, you got nothing.
 
do this on your page2:

session("myemp")=emp then

this session variable is to you and you can use it...

-DNG

 
Place it in a hidden field:

Code:
<tr bordercolor="#CCCCCC"> 
    <td>
<div align="center">
<font color="#000000" size="2" face="Arial"><%=emp%></font>
[b]
<input type='hidden' name='lstemp' value="<%=emp%>"
[/b]
</div>
    </td>
    <td><div align="left"><font color="#000000" size="2" face="Arial"><%=rs("duty")%></font></div></td>
      <td> <div align="center">
          <input name="txtmscore" type="text" id="txtmscore" size="5">
        </div></td>
  </tr>
 
yes..either hidden or session variable works fine...

-DNG
 
changes made(included the session)...still nothing for the userid ppl but worse, it's now reading only the 1st score only and inserting that in the db.i already had 1 session. can that be conflicting:

<%
enablesessionstate = true
Response.Expires = -1000 'Make sure the browser doesn't cache this page
Response.Buffer = True 'enables our response.redirect to work
userid1 = session("user1")
emp = session("myemp")



code as follows:

Sub Next2
dim rs
dim cn
Dim sql, sql1
dim i,score

date1=request.form("txtdate")
per=request.form("lstper")
pos=request.form("lstpos")
dept=request.form("lstdept")
pjt=request.form("lstpjt")

Set cn = Server.CreateObject("ADODB.Connection")
cn.Open(Conn)

Set rs = Server.CreateObject("ADODB.Recordset")

txtmscore = request.Form("txtmscore")
score = split(txtmscore,", ")

for i = 0 to UBound(score)-1
sql = "INSERT INTO mdutyscore (userid, mdscore) VALUES ('" & emp & "' ,'" & score(i) & "' )"


cn.Execute(sql)
next

end sub
 
did anyone find a bug in that or can someone tell me why the userid is not being retrieved?

Thnx a lot to DotNetGnat and Kendel for their valuable contribution. Bravo!

Gold Pearl.
 
I was missing the closing tag in the hidden input.

<input type='hidden' name='lstemp' value="<%=emp%>">

Try it again see how it work. Session variable should do the job too.
 
One way to test it is setting the type='text' for now, make sure the emp value is there. You can set back to hidden once it works.
 
when you are getting the recordset like this on your page2...

userid duty1 score1
userid duty2 score2
userid duty3 score3

you need to loop through to build the session variable which can later split it...

something like this:
emp=""
do unitl rs.EOF then
emp= emp & "," & rs("emp")
loop

session("myemp")=emp

then on the next page...you can do a split...

emp=split(session("myemp"),",")

-DNG

 
Where did you set the value of emp anyways, I didn't see that anywhere in your code.
 
i'll try the latest 'posts' for sure and be back with a feedback tomorrow morning. where am situtated now, it's 9 pm and i need to go home.

thks again and catch u in 11 hours! (if u r online..both of u :))

Gold Pearl
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top