update on check

A

A.Dagostino

hi
i need to update an SQL Table when user select or unselect a checkbox
control.
How Can i do?
Thanks
Alex
 
B

Bob Barrows [MVP]

A.Dagostino said:
hi
i need to update an SQL Table when user select or unselect a checkbox
control.
How Can i do?
Thanks
Alex

Database type and version, please. "SQL Table" may mean "MS SQL Server", but
it does not have to ...
Also, please provide some information about the table. It would really help
if you provided the CREATE TABLE script for the table (www.aspfaq.com/5006).
Just show the relevant columns.

And give us a little information about the form you are using. Are you using
POST or GET? What is the name of the checkbox? Are you submitting it to
itself or to another page?
 
A

A.Dagostino

the table is a MS SQL Server table
here is the script
<%


'I LOAD A TABLE WITH THE COLUMNS AND A CHECKBOX
response.expires = 0

dim sql, rs
set rs = createObject("ADODB.recordset")
rs.open "USE At_Wrk_Db SELECT IdArticolo, MGAA_MBIV_Id, MGAA_MBDC_Classe,
MGAA_Matricola, descrizione, Statoarticolo, selezione FROM
WRK_ListaArticoli",connessioneDB, 3, 3

response.Write("<input type=""button"" value=""Chiudi finestra""
name=""CloseWin"" onclick=""javascript:chiudifinestra();""</button></td>")
response.write "<table cellspacing=""3"" cellpadding=""2"" border=""1""
rules=""groups"" frame=""borders"" bordercolor=""#cococo""
style=""behavior:url(tabEdit.htm)"" slcolor=silver hlcolor=black>"
'response.write "<table border='1'>"
while not rs.eof
'response.write "<tr style=""cursor: hand;""
onclick=""selectSeekRow(this);"""
response.write "<tr>"
response.write "<td>" & rs("IDarticolo") & "</td>"
response.write "<td>" & rs("MGAA_MBIV_Id") & "</TD>"
'response.write "><td style=""padding-left:3px;border-bottom:1px solid
black;border-right:1px solid black""><font size=""1"">"
response.write "<td>" & rs("MGAA_MBDC_Classe") & "</td>" '&
"</font></td><td style=""border-right:1px solid black;border-bottom:1px
solid black;"">"
response.write "<td>" & rs("MGAA_Matricola") & "</td>" '& "</td><td
style=""padding-left:5px;border-bottom:1px solid black;"">"
response.write "<td>" & rs("descrizione") & "</td>"
style=""border-bottom:1px solid black;"">" & posizione &" </td>"


'I CALL A VBSCRIPT SUB(WHITH PARAMETERS) WHEN THE ONCLICK EVENT IS ACTIVATE
response.write "<td><input type='checkbox' name='ChkSelezione'
onclick=""ChkSelezione_onClick(this.checked," & rs("MGAA_Matricola") &
");""></td>"


response.write "</tr>"
rs.movenext
wend
response.write "</table>"


%>

HERE IS THE SUB

Sub ChkSelezione_onClick(Check, Matricola)
dim Sql_Aggiorna_Sel, bit, rs
//msgbox (chek & " " & Matricola)
if check=true then
bit=1
else
bit=0
End if
Sql_Aggiorna_Sel= "USE At_Wrk_Db UPDATE WRK_ListaArticoli SET Selezione =" &
bit & " WHERE MGAA_Matricola=" & "'" & matricola & "'"
connessioneDB.execute(Sql_Aggiorna_Sel)

end sub

* connessioneDB is defined in the GLOBAL.ASA it seems to be Protected.

thanks for your help
Alex
 
B

Bob Barrows [MVP]

www.aspfaq.com/5006

Bob Barrows
A.Dagostino said:
the table is a MS SQL Server table.

What version of SQL Server?
here is the script
<%
You misunderstood what I meant by a "CREATE TABLE" script. Please go to the
link I provided and read the article:
www.aspfaq.com/5006
Also, I noticed an onclick event procedure containing some code to create a
sql statement. Does this imply that you want to perform this update from
client-side code without submitting your form? If so, this is not an ASP
issue and you should provide the information I requested in a post to a more
relevant newsgroup like microsoft.public.scripting.vbscript

Bob Barrows
 
A

A.Dagostino

ok i try to explain you my problem from the begin.
I have a page whith n articles loaded in an html table.
Now users can select only one article.
I need to permit a multiselction to the users.
So, if i can't modify the original template I have Created a window whit
the articles and checkbox controls. Now i need to give the result of the
selection to anaother page.

How can i do?
P.S i'm not very espert of web applications
Thanks
Alex
 
B

Bob Barrows [MVP]

You're telling me everything except what I asked for: I need to know about
your database. I need to know about the columns in your database table (not
all of them - just the relevant ones - the primary key, the field that will
contain the data controlled by the checkbox). Not just their names ... I
need to know their datatypes. Again, the best way to convey that information
can be found in www.aspfaq.com/5006.

From your description, it no longer sounds as if you need a client-side
solution, so we will continue this discussion here. Please provide the
information requested in my first paragraph so I can begin to help you.

Also, I need to know what you want the application to do after the user
clicks the checkboxes in your html table. It is easy enogh to process the
multiple checkbox selections in another page ... I just need to know what
you want that page to do with the records that were selected.

Here is a quick generic demonstration:

page1.htm:

<html><body>
<form method="post" action="page2.asp">
<table>
<tr>
<td>
<input type="text" value="First record" name="data1">
</td>
<td>
<input type="checkbox" name="selector" value="1">
</td>
</tr>
<tr>
<td>
<input type="text" value="Second record" name="data2">
</td>
<td>
<input type="checkbox" name="selector" value="2">
</td>
</tr>
<tr>
<td>
<input type="text" value="Third record" name="data3">
</td>
<td>
<input type="checkbox" name="selector" value="3">
</td>
</tr>
</table>
<input type="submit" value="Submit">
</form>
</body></html>


page2.asp:

<%
dim key
Response.write "Here is all the data submitted by the form:<BR>"
for each key in Request.Form
Response.Write key & ": " & Request.Form(key) & "<BR>"
next

dim selected
selected=request.form("selector")
Response.write "<BR>The following records were selected:<BR>"
Response.write selected & "<BR><BR>"
Response.write "Here is where I process the selections:<BR>"
dim ar, i, id, data
if len(selected) > 0 then
response.write "<table border=""1""><tr><th colspan=""2"">"
response.write "Selected Data" & "</th></tr>"
ar=split(selected,",")
for i = 0 to ubound(ar)
id=trim(ar(i))
data = request.form("data" & id)
ar(i)="<tr><td>" & id & "</td><td>" & data & "</td></tr>"
next
response.write join(ar,vbcrlf)
response.write "</table>"
else
response.write "No records were selected"
end if
%>

Bob Barrows
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,147
Messages
2,570,837
Members
47,385
Latest member
Joneswilliam01

Latest Threads

Top