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

Returning Confirm to HTML from JS function 1

Status
Not open for further replies.

Dagon

MIS
Jan 30, 2002
2,301
0
0
GB
That works fine and the button action is cancelled if the user clicks Cancel on the confirm box. But I really want it to be a bit more sophisticated and take parameters to determine whether it displays the dialog box or not.

As a first step, I have a JS function such as:

Code:
function checkLivePolicies(policyCount) {
  return confirm('This has ' + policyCount + ' live policies which will cancelled.  Are you sure?');
}

I then change my button to:

onclick="checkLivePolicies(3)"

It executes the function and shows the confirm box. But it still executes the action of the button, even if I choose CANCEL. Can anyone tell me if there is a way to fix this?

 
Sorry, this got garbled. It was supposed to say this:

I created a button in a form with a confirm dialog to allow the user to cancel the action using:

Code:
<button>
...
onclick="return confirm('Are you sure?')" 
</button>

That works fine and the button action is cancelled if the user clicks Cancel on the confirm box. But I really want it to be a bit more sophisticated and take parameters to determine whether it displays the dialog box or not.

As a first step, I have a JS function such as:


CODE
function checkLivePolicies(policyCount) {
return confirm('This has ' + policyCount + ' live policies which will cancelled. Are you sure?');
}
I then change my button to:

onclick="checkLivePolicies(3)"

It executes the function and shows the confirm box. But it still executes the action of the button, even if I choose CANCEL. Can anyone tell me if there is a way to fix this?


 
Code:
onclick="[red]return[/red] checkLivePolicies(3)"




Mark

"You guys pair up in groups of three, then line up in a circle."
- Bill Peterson, a Florida State football coach
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top