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

YesNo Msgbox 2

Status
Not open for further replies.

Kendel

Programmer
Apr 24, 2002
1,512
US
Hi all,

This must be a simple one but I forgot the syntax. Do you know how to make a YesNo msgbox on an image.

Thanks.
 
a YesNo msgbox [highlight]on an image[/highlight]
???

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Sorry for not to be clear. What I meant was: when user click on an image, a yesno msgbox will be popup.

Thanks.
 
Hi there

Try this, Create the shell
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Popup "The text of your message here....",10 _
,"The title of your message box", vbInformation+vbYesNo

'The 10 is number of second box will wait for input.

'Getting result of button clicked:
If intClicked = 1 Then
wscript.Echo "ok"
Else
wscript.Echo "no"
End if
regards aco
 
Hello Kendel,

If simplied to essential, the image tag with handling is:

[tt] <img src="abc.jpg" onclick="img_msg" />[/tt]

with the sub/function img_msg within which contains the msgbox:

[tt] iret=msgbox("prompt msg",vbYesNo,"title here")[/tt]

The return value can be checked against vbYes or vbNo.

vbYesNo=4, vbYes=6 and vbNo=7 are constants recognized automatically by the vbs engine and do not need to define explicitly.

regards - tsuji
 
tsuji, that's exactly what I need. Thank you!

Thanks for your help to aco636, I forgot to tell you that I'm working on a web app.

-kendel
 
<script language="vbscript">
Function confirmDelete()
answer = MsgBox("Are you sure you want to delete this one?",4,"Delete")
If answer = 6 Then
return true
Else
return false
End If
End Function
</script>

<img href="javascript: myDeleteFunction(document.formName, 'Delete')" src="abc.jpg" onclick="return confirmDelete"/>

No matter what my answer is, it will always delete my record. What am I doing wrong here?
 
And what about this ?
Function confirmDelete()
answer = MsgBox("Are you sure you want to delete this one?",4,"Delete")
If answer = 6 Then
myDeleteFunction(document.formName, "Delete")
return true
Else
return false
End If
End Function
</script>

<img src="abc.jpg" onclick="return confirmDelete"/>

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks PHV, it didn't work because I'm trying to call a javescript inside vbscript. I have to use javascript for both. Thanks anyways.
 
Kendel,

In your vbs function, instead of return true/false like js function, it is the function name which is returned. Hence, use instead this.
[tt]
Function confirmDelete()
answer = MsgBox("Are you sure you want to delete this one?",4,"Delete")
If answer = 6 Then
myDeleteFunction(document.formName, "Delete")
confirmDelete = true
Else
confirmDelete = false
End If
End Function
[/tt]
But, I am not sure of the call to the line myDeleteFunction up there coupled with your href javascript protocol. May be I should look into it. But, that is how return is done in vbs.

- tsuji
 
Correction:

OK, I see now the line myDeleteFunction() is from PHV's revision and not in Kendel's. I should not have put it there if I stick to Kendel's. It would not recognize the namespace the jscript is sitting. (If it's a vbscript, I would also add a "call" keyword in front.) So, as such, it would bound to cause trouble.

This is the revision of the original form.
[tt]
Function confirmDelete()
answer = MsgBox("Are you sure you want to delete this one?",4,"Delete")
If answer = 6 Then
confirmDelete = true
Else
confirmDelete = false
End If
End Function
[/tt]
- tsuji
 
Further note:

After looking more close your tag, I would propose doing instead the following.
[tt]
<a href="javascript:myDeleteFunction(document.formName, 'Delete');"><img src="abc.jpg" onclick="confirmDelete" /></a>
[/tt]
Whereas, the function confirmDelete is this. (Now, I see what you intend to do with the return.)
[tt]
Function confirmDelete()
answer = MsgBox("Are you sure you want to delete this one?",4,"Delete")
If answer = 6 Then
'confirmDelete = true
window.event.returnValue = true
window.event.cancelBubble = false
Else
'confirmDelete = false
window.event.returnValue = false
window.event.cancelBubble = true
End If
End Function
[/tt]
Main functionality is on the returnValue and cancelBubble properties. I even comment out confirmDelete return. You can make it a sub no problem.

- tsuji
 
tsuji, your solution looked logical to me but when I tested it, it didn't popup the confirmation and deleted the record.

I think javascript & vbscript don't work together in some case.
 
Kendel,

Let me device a demo of concept.
Code:
<html>
<head><title>demo</title>
<script language="javascript">
function myDeleteFunction(obj,s) {
	alert("you're here-myDeleteFunction");
}
</script>
<script language="vbscript">
Function confirmDelete()
	answer = MsgBox("Are you sure you want to delete this one?",4,"Delete")
	If answer = 6 Then
		'confirmDelete=true
	Else
		'confirmDelete=false
		window.event.returnvalue=false
		window.event.cancelbubble=true
	End If
End Function
</script>
</head>
<body>
<form name="formName">
<div><h3>[1] testing simple anchor</h3>
<a href="javascript:myDeleteFunction();">adfasdf</a>
</div>
<div><h3>[2] testing only confirmDelete</h3>
<img src="[URL unfurl="true"]http://tek-tips.com/images/partnerbtn120x60.gif"[/URL] onclick="confirmDelete()" />
</div>
<div><h3>[3] testing my proposed solution of nested tag construction</h3>
<a href="javascript:myDeleteFunction(document.formName, 'delete');"><img src="[URL unfurl="true"]http://tek-tips.com/images/partnerbtn120x60.gif"[/URL] onclick="confirmDelete()" /></a>
</div>
<!-- this span is the original poster's construction -->
<div><h3>[4] original tag construction - would fail</h3>
<img href="javascript:myDeleteFunction();" src="[URL unfurl="true"]http://tek-tips.com/images/partnerbtn120x60.gif"[/URL] onclick="confirmDelete()" />
</div>
</form>
</body>
</html>
- tsuji
 
Thanks again tsuji.

For this deme, if my answer is yes, it should call the javascript function, correct? But it didn't; event when I add
window.event.returnValue = true
window.event.cancelBubble = false
to "Yes".

The "No" part did work as expected.
 
I'm sorry. It's my bad. Your demo did work as expected. I got to give you another star. I dodn't understand why it didn't work with my code.
 
Kendel,

I spared the two lines for "yes" just because it is the default behavior. Adding them back should behave the same.

I tested yes in the [3], it bubbles up to a-href tag and fires the javascript function as anticipated. Did you find it not?

- tsuji
 
Kendel,

Ok, posted the same time. You answered the question.

- tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top