The Facebook Platform   
    Home  |   Learn AJAX  |   Forum  |    Register  |    Submit Resource  |   Submit Article   |   Contact Us
 

JavaScript

Home JavaScript

JavaScript Confirm Function

Category: JavaScript   |   Comments (0)

Confirm is a very simply yet a smart function that can be used by developers to launch sets of function or simply to increase interaction with users. In terms of security, it's not necessarily as strong as the CAPTCHA format but another user input can easily provide options on their activities online. If the right set of functions is added in this function, additional interaction and information could be added.


Sponsored Links
 

 


The simplicity of confirm function is on its syntax:


confirm ()


Adding this function in the application will automatically create a message asking the user to confirm. Although it's not added in the code, the confirm function will offer two choices: "OK" and "CANCEL". Obviously, "OK" would mean "Yes" and "CANCEL" means the transaction or the user do not agree with the interaction.


Developers have a variety of options on what to do with this function. But these options can be divided into two groups: the string literal and additional function.


The string literal is a very straightforward. Developers simply encode the question they want to ask. Any question they would ask will be displayed in the pop-up box titled "Confirm". Since it's a string literal and no additional code, nothing much will happen even when the buttons are pressed.


On the other hand, developers can do so much more with the function by adding actions based on user's choices. The possibilities are practically endless because the user's action will trigger additional interaction.


Essential If…Else Function


The confirm function may look like an impressive pop-up tool for developers but it's not going to do anything without additional functions that will react to users input. Among those functions is the "If…else". Simply put, the presence of if…else will allow developers attach prompts and additional actions based on user input.


When if…else is used, the confirm function becomes part of its variable. Here's an example:


var ask = "how are you today?"
if (ask)
alert ("Cool")
else
alert ("it happens")


The above sample uses a simple pop-up alert interaction. There is no real change made on the application except message pop-ups in the website to ask "how are you today?". As already indicated, "OK" and "CANCEL" means "yes" and "no" respectively so there is no need to assign any reaction.


Additional Actions


Developers will not be limited on simple reaction as they can push the function further. A good example is to add "window.location" after a specific alert. Add this to one of the "if…else" with the intended website so that the user will be automatically redirected. Here's an example:


var ask = "how are you today?"
if (ask)
alert ("Cool")
else
alert ("it happens")
window.location = "http://learntobehappy.com"


Of course, the "window.location" can be replaced with other functions depending on the developer's preferences.



Sponsored Links
 

 

Confirm function can be considered as a gateway that can be harnessed by developers so that the website will fully interact with its users. From simple alert messages to redirections, there will always be options for developers as functions can be attached with the choices provided by the confirm function.



Read Next: Referring JavaScript Files in Ajax


 
Post Your Comment
Members - Please Click here Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification:
 
 Subscribe    

Post Your Comment via FaceBook

Connect with Facebook



 
Comments
 
 
 
 

Sponsored Links

 

Copyright © 2005 - 2010 AjaxWith.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape