Forums

ASP

This topic is locked

Javascript Loop and ASP insert

Posted 13 Mar 2007 01:21:53
1
has voted
13 Mar 2007 01:21:53 Jean Marie posted:
I am able to insert one record at a time in a sql database using ASP and Javascript.
However, if my form contains more than 1 record, my ASP insert crashes.

Does any one have a Javascript code to allow me to do this in Dreamweaver?

Replies

Replied 13 Mar 2007 15:06:22
13 Mar 2007 15:06:22 MARK COKER replied:
Hi

I think that the best way to approach this is to create the loop in asp and surround the insert script with this loop, something like this


<%dim iCount, sCounting
sCounting = request.Form("HFImmsCount"

For iCount = 1 to sCounting%>
<%

if(request.form("cb"&icount) <> "" then cmdup__cb = request.form("cb"&icount)

if(request.form("HFUser" <> "" then cmdup__HFDel = request.form("HFUser"

if(request.form("hfid"&ICOUNT) <> "" then cmdup__hfid = request.form("hfid"&ICOUNT)

if(request.form("HFDate" <> "" then cmdup__varwhen = request.form("HFDate"

%>
<%
if request.form("cb"&icount) = 1 then
set cmdup = Server.CreateObject("ADODB.Command"
cmdup.ActiveConnection = MM_GPImms_STRING
cmdup.CommandText = "UPDATE dbo.TblEmisImms SET Deleted = '" + Replace(cmdup__cb, "'", "''" + "', DeteledBy = '" + Replace(cmdup__HFDel, "'", "''" + "', DeletedWhen_ ='" + Replace(cmdup__varwhen, "'", "''" + "' WHERE ID = '" + Replace(cmdup__hfid, "'", "''" + "' "
cmdup.CommandType = 1
cmdup.CommandTimeout = 0
cmdup.Prepared = true
cmdup.Execute()
end if
%>

<%next%>
<i></i><font color=blue></font id=blue>

What i have done here, is that i have a form, on that form i repeat each record with a tickbox next to it. If the user would like to delete they simply tick the box and click update and then I run a server.transfer to go to the insert page which contains the script above. Once that scrip has run, i simply do a response.redirect to get the user back to the form

Thanks

Marcus
Replied 13 Mar 2007 19:11:15
13 Mar 2007 19:11:15 Jean Marie replied:
Thank you Marcus.
If the javascript form includes several rows, how, upon clickin on submit, will the ASP loop parse one row at a time?

Thank you for insight. I really appreciate your help.

Regards,

Jean-Marie

<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
I am able to insert one record at a time in a sql database using ASP and Javascript.
However, if my form contains more than 1 record, my ASP insert crashes.

Does any one have a Javascript code to allow me to do this in Dreamweaver?
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
Replied 14 Mar 2007 13:49:33
14 Mar 2007 13:49:33 MARK COKER replied:
Hi

I think you would need to use asp to loop though the form and bring back the right number of form input boxes. In my case i just repeated the recordset and named each tickbox with the ID number of the field

No javascript used

Thanks

Marcus

Reply to this topic