Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Web
Expertise: Intermediate
Jun 3, 1999

Implement a Confirm Box That Redirects Based on a User's Choice

You can easily create a function that redirects to a different page depending on a user's choice of OK or Cancel. You should use JavaScript's confirm command and then based on what is returned change the location property of the window object appropriately. For example:
 
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
function confirmRedirect(prompt, okURL, cancelURL)
{
	var confirmResult;

	// ask the user to chose either OK or Cancel
	confirmResult = confirm(prompt);

	// switch to a new URL based on the user's choice
	if (confirmResult) {
		window.location = okURL;
	} else {
		window.location = cancelURL;
	}
}
// -->
</SCRIPT>
</HEAD>
<BODY>
<FORM>
Click here to go to a new page:<BR>
<INPUT TYPE="button" VALUE="New Page"
onClick="confirmRedirect('Where do you want to go
today?','good.htm','bad.htm')">
</FORM>
</BODY>
</HTML>
Boris Feldman
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date