/    Sign up×
Community /Pin to ProfileBookmark

javascript confirmation with 2 levels

Hi,

I’m new to javascript and writinig a function for an ASP.NET C# webform.
I have a delete command button on the form.
When the user clicks on the form following logic occurs:

if labelcontrol1.value has a value then

var result = confirm(“Are you sure you want to delete”);

if(result)
{
fire the C# server side click event code which will delete record.
}
else
{
do nothing.
}

else

alert (Please choose a record.”) “Can’t delete unless a record is chosen.”

end if

sorry, i don’t know the syntax yet of javascript.

the main problem is how to get the server side click event to fire if the Okay button is choosen in the javascript confirmation window?

humbly requesting help.

thanks

haggisns

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@FangOct 13.2005 — Something like this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>form confirm</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<script type="text/javascript">
function check() {
var f=document.form1;
if(f.labelcontrol1.value) {
if(confirm("Are you sure you want to delete")) {
return true;
}
}
else {
alert("Please choose a record.nCan't delete unless a record is chosen.");
}
return false;
}
</script>

</head>
<body>
<form action="deleteRecord.cgi" method="post" name="form1" onsubmit="return check();">
<div>
<input type="text" name="labelcontrol1">
<button type="submit">delete</button>
</div>
</form>
</body>
</html>
Copy linkTweet thisAlerts:
@haggisnsauthorOct 13.2005 — Hi,

thanks for response.

I am using ASP.NET web control button.

I am using the add.attributes method to add the javascript from a

.js file.

When I run the script it continues on to the click event in the code behind page for the button. I want to stop it from going to the code behind page.

Should I have an invisible checkbox to hold the value of true/false and then read it from the code behind page?

thanks

haggisns
Copy linkTweet thisAlerts:
@haggisnsauthorOct 13.2005 — wait,

forget that idea,

the whole point is not to run server side code unless I truly want to

delete a record.
×

Success!

Help @haggisns 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 5.15,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...