Skip to content

Instantly share code, notes, and snippets.

@serin113
Created July 20, 2012 16:00
Show Gist options
  • Save serin113/3151549 to your computer and use it in GitHub Desktop.
Save serin113/3151549 to your computer and use it in GitHub Desktop.
javascript code for easily creating user-prompted popups
function popUp(t, m, pp){
// intialization of return value
var ret;
/*
var m is the message in the popup (required)
var t is the type of popup (required)
var pp sets a placeholder for the input (prompt only)
possible values of t: "alert", "confirm", "prompt" (include the quotation marks)
any value of m and pp must be enclosed within quotation marks
*/
//show message
if (t=="alert"){alert(m);}
//get confirmation (returns "true" or "false") and get value
else if(t=="confirm"){r=confirm(m);}
//get prompt (setting pp is optional) and get value
else{r=prompt(m, pp);}
//return value if t is "confirm" or "prompt"
if(t=="confirm"||t=="prompt"){ret=r;}
//return nothing if t is "alert"
else{ret=""}
//final return value of function
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment