954,597 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

javascript confirm() function problem????

Hi Everyone,
I am using javascript code for removing some records. When i am click on delete selected button. I want this should demand one confirm button in which i want if we click OK in confirm box then the record should be removed from database and if i will click on CANCEL button then it should not be removed that record.
I have used some code for this but in this case when i click on CANCEL button after that this is also removing records that i does not want.

So i am sending code for javascript which i am using for this. Please help me what code i should use for this application.

here is code which i am using:----

function validate()
{
var confirmMessage="Are you sure to Delete these Details from Database ! " ;

if(confirm(confirmMessage)==false)
{

return false;

}
}


and this is delete button which i am using in my code: <input name="Delete" type="submit" class="footerlink" value="Delete Selected" onClick="return validate()">


Please help me what javascript code i should use for this. It is very urgent for me.
Thanks,
Gagan

gagan22
Junior Poster
131 posts since Feb 2009
Reputation Points: 10
Solved Threads: 0
 

Do it this way:

<html>
<head>
<title></title>
<script type="text/javascript">
<!--
function validate( form ) {
   if ( !confirm("Are you sure to delete these details from database?") ) {
      return false;
      } else { return true;
   }
}
// -->
</script>

</head>
<body>
<form action="process.php" method="post" id="form1" onsubmit="return validate( this );">
<div>
<input type="submit" value="submit" id="sbm" name="sbm" />
</div></form>
</body>
</html>
essential
Posting Shark
974 posts since Aug 2008
Reputation Points: 114
Solved Threads: 138
 

that's way over-complicated the function. You don't need to pass the form and you don't need if-blocks

function validate()
{
  return confirm("Are you sure to delete these details from database?");
}
ShawnCplus
Code Monkey
Team Colleague
1,583 posts since Apr 2005
Reputation Points: 526
Solved Threads: 268
 
onClick="return confirm('Are you sure to delete');"

JUST MODIFY THE INPUT HTML.

mail2saion
Posting Whiz in Training
247 posts since Apr 2009
Reputation Points: 26
Solved Threads: 44
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You