/    Sign up×
Community /Pin to ProfileBookmark

I have two buttons on my page. One is exit and the other is cancel and only one is visible at a time. I would like to know if somehow in Javascript can I tell which object exist and perform certain VB code displaying a confirmation message when clicking on cancel when the cancel button exists and just closing the page when the exit button exists.

thanks,

Cheryl

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@so_is_thisDec 13.2006 — Are you talking about this? ...when you say VB code?
<i>
</i>&lt;script type="text/vbscript"&gt;
&lt;!--'
Dim obj, id
id = "MyButton"
Set obj = Document.getElementById(id)
If obj Is Nothing Then
MsgBox id &amp; " does not exist."
Else
MsgBox id &amp; " does exist."
End If
'--&gt;
&lt;/script&gt;
Copy linkTweet thisAlerts:
@cmkohrmannauthorDec 13.2006 — Ok, I'm new to JavaScript but my boss thought that I should be able to do something like this....

create the function to check

if the btnCancel exists or is enabled then

MsgBox id & " Save before cancel?"

elseif btnExit exists or is enabled then

close the window.


Are you saying that I can identify by the elementID to see what button was pressed?

Thanks for your fast response.
Copy linkTweet thisAlerts:
@so_is_thisDec 13.2006 — Well, this ain't JavaScript. And, more than that:
[code=html]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>VBScript Event Handlers</title>
<script for="MyCancelButton" event="OnClick" type="text/vbscript">
Set obj = Window.event.srcElement
MsgBox obj.id & " was clicked and has a value of """ & obj.value & """."
</script>
<script for="MyExitButton" event="OnClick" type="text/vbscript">
Set obj = Window.event.srcElement
MsgBox obj.id & " was clicked and has a value of """ & obj.value & """."
</script>
</head>

<body>
<p><button type="button" id="MyCancelButton">Cancel</button></p>
<p><button type="button" id="MyExitButton">Exit</button></p>
</body>
</html>[/code]
Copy linkTweet thisAlerts:
@felgallDec 13.2006 — Of course that will only work on Internet Explorer as no other browser can run vbScript.
×

Success!

Help @cmkohrmann spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.13,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,
)...