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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Msgbox variables Sever/Client Mix 1

Status
Not open for further replies.

itflash

Programmer
Jul 18, 2001
535
GB

Hi all

I have a problem

My VBscript code is running as normal, server side.
One of my buttons allows the user to delete from the database. However, before they delete, I would like to give them a confirmation button.

Is there a way to use the msgbox function on the server side scripts so I can use the form variables and other variables?


Thanks
[spin] ITFlash [spin]
 
you should jsut be able to add a if statement in the code with a msgbox with vbOKCANCEL. post the code and I might be able to determine better. I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
 

How can I encase the following code with a msgbox to say "ok to delete? yes/no"

Also, how do I trap for the execute method returning an error? I tried "if err", but it didnt work.



Thanks


' Check if a user was selected and if delete was pressed
' If so, delete the appropriate user

if isnumeric(request.form("userlist")) and _
not isempty(request.form("delete)) then
connectionstring = "DSN=sql-db;UID=;PWD="
set sqldb = Server.CreateObject("ADODB.Connection")
sqldb.CommandTimeout = 1000
sqldb.open ConnectionString
cSql = _
"DELETE FROM iuser WHERE userid=" & _
rtrim(request.form("userlist1")) & ";"
sqldb.Execute (cSql)
end if
 
easiest way I can think of to do this, (delete msg) is do it onClcik of the delet button.
sub mess()
Dim MyVar
MyVar = MsgBox ("Are you sure you want to delete option?", 4)
end sub


I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
 

I've been having a look/poke around, looks like you have to submit the form in some way to share variables.

If I did it your way, can I put all my code on the client side and will it still work?

Thanks
 
have you tried
Dim MYmsg

if isnumeric(request.form("userlist")) and _
not isempty(request.form("delete)) then
MYmsg = MsgBox ("Are you sure you want to delete option?", 4)
connectionstring = "DSN=sql-db;UID=;PWD="
set sqldb = Server.CreateObject("ADODB.Connection")
sqldb.CommandTimeout = 1000
sqldb.open ConnectionString
cSql = _
"DELETE FROM iuser WHERE userid=" & _
rtrim(request.form("userlist1")) & ";"
sqldb.Execute (cSql)
end if

not sure but it looks viable to me. As long as yes is returned or true then the code should follow through to the sql statement. let me know now I'm curious. never tried sticking a msgbox in there before I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
 
>Is there a way to use the msgbox function on the server >side scripts so I can use the form variables and other >variables?

I thought the MsgBox Function could only be used Client Side?
Rob
Just my $.02.
 
OK...rtshort is correct on the server side. I tried and tried and could not get it to work. so I wrote a quick function to give the message box onsubmit. wasn't sure of your page so I wrote it for a validation of length of charaters. should be able to modify it easily. if you need help with that let me know the form etc names

<html>
<head>
<SCRIPT LANGUAGE=&quot;VBScript&quot;>
dim validation
Function MyForm_OnSubmit
validation = True

If Len(Document.MyForm.MyBox.Value) > 2 Then
MsgBox &quot;You have entered too many characters!&quot;,8

validation = False

End If

If (Document.MyForm.text1.Value) = &quot;&quot; Then
MsgBox &quot;You have forgotten to fill in the input box!&quot;,8

validation = False

End If

If validation = True Then
MyForm_OnSubmit = True

Else

MyForm_OnSubmit = False

End If

End Function
</script>
</HEAD>
<BODY>
<form METHOD=&quot;POST&quot; ACTION=&quot;blah.asp&quot; name=&quot;MyForm&quot;>
<input TYPE=&quot;submit&quot; VALUE=&quot;Submit Info!&quot; name=&quot;submit&quot;>
<input type=&quot;text&quot; name=&quot;text1>
<INPUT TYPE=&quot;submit&quot; Value=&quot;Submit&quot;>
</form>
</body>
</html>
I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
 
that was messy here
<html>
<head>
<SCRIPT LANGUAGE=&quot;VBScript&quot;>
dim validation
Function MyForm_OnSubmit
validation = True

If Len(Document.MyForm.text1.Value) > 2 Then
MsgBox &quot;You have entered too many characters! You need fewer characters before I will submit this form&quot;,8

validation = False

End If

If (Document.MyForm.text1.Value) = &quot;&quot; Then
MsgBox &quot;You have forgotten to fill in the input box!&quot;,8

validation = False

End If

If validation = True Then
MyForm_OnSubmit = True

Else

MyForm_OnSubmit = False

End If

End Function
</script>
</HEAD>
<BODY>
<form METHOD=&quot;POST&quot; ACTION=&quot;blah.asp&quot; name=&quot;MyForm&quot;>

<input type=&quot;text&quot; name=&quot;text1&quot; size=&quot;10&quot;>
<INPUT TYPE=&quot;submit&quot; Value=&quot;Submit&quot;>
</form>
</body>
</html>
I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
 
Thanks for the help/replies

This is what I did:


The form posts itself as:
-------------------------
<form name=MainFrm method=&quot;POST&quot; action=&quot;usermaint.asp&quot;>


The delete button is:
---------------------
response.write(&quot;<input type='button' value='Delete'
name='Delete' onclick='deleteonclick()'>&quot;)


Another field to hold the result of the delete button
-----------------------------------------------------
response.write(&quot;<INPUT TYPE=HIDDEN NAME='deletemode' VALUE='false'>&quot;)


The onclick Script
------------------

<SCRIPT LANGUAGE=&quot;VBScript&quot;>
function deleteonclick()

x = MsgBox(&quot;Are you sure you wish to Delete this
User?&quot;,vbQuestion + vbYesno,&quot;Title&quot;)
mainfrm.deletemode.value=x
if x=vbYes Then
deleteonclick=false
document.mainfrm.submit
end if

end function
</SCRIPT>


Then in my code, I check what the user pressed.
This shows the other buttons that could have been pressed
----------------------------------------------------------
if not isempty(request.form(&quot;Amend&quot;)) and request.form
(&quot;Amend&quot;) <> &quot;&quot; _
and not isnull(request.form(&quot;Amend&quot;)) then
amendfunction
else
if not isempty(request.form(&quot;New&quot;)) and request.form
(&quot;New&quot;) <> &quot;&quot; _
and not isnull(request.form(&quot;New&quot;)) then
newFunction
else
' must have pressed delete
if cint(request.form(&quot;DeleteMode&quot;)) = vbYes Then
deletefunction
end if
end if
end if


Thats IT!

Thought I'd share my conclusion to you all.
Please tell me if this does not make sense (if you are interested at all) or if anyone has a better way of doing it.

Thanks
ITFlash
[thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top