Reputation: 701
i have a requirement to show javascript Ok/Cancel option on page load. So, when the user is redirected from the previous page to this page, based on some logic in the query string, we have to display javascript OK/Cancel (page is not yet rendered here). Once the user clicks, we have to load different type of data (server side execution) based on OK/Cancel. what is the best way of accomplishing this task? thanks.
Upvotes: 0
Views: 2020
Reputation: 10080
Vanilla popping up a dialog:
if (confirm("Your question"))
{
// do things if OK
}
Although you should look into the other answers/comments here, as this will break if the user has disabled javascript.
Edit: If you want to load more info after the dialog, you will have to use ajax. Since your answer is quite general, I can only point you in the direction of the jQuery ajax functions for now.
Upvotes: 0
Reputation: 3126
Load a small html page stub with basic formatting, then popup your dialog box.
Depending on the response, populate the page's contents using an ajax request.
Here's some very basic example code. See this tutorial for examples of how to make an Ajax call in javascript.
<html>
<head><!-- Head Contents --></head>
<body>
<!-- Basic body styling -->
<noscript>This page works best with scripts enabled</noscript>
<script type="text/javascript">
// Show Dialog Box
if(option1) {
// Do Ajax call
// Set page contents
} elsif (option2) {
// Do other ajax call
// Set page contents
}
</script>
</body>
</html>
Upvotes: 0
Reputation: 27529
Ignoring the various problems with this requirement, here's the simplest approach that I can think of.
Execute the following in Javascript:
confirm()
to determine the course of actionYour <noscript>
element should contain directions on what a user who has javascript disabled should do... something more helpful than 'Please enable javascript' would be nice, but it's your call.
Upvotes: 1