Tag Archives: prompt function

Javascript Confirmation and variations

Ok so this is some really old JavaScript but I used way back when I first started so keep it nice and take a look if you like.

Regular confirmation JavaScript


1
2
3
4
5
6
7
8
9
10
<script type="text/javascript">
<!-- 
function confirmation() { 
var answer = confirm("Welcome to Tom's Blog if you want to come in select \n\"OK\"\nor\n\"Cancel\" if you want to leave") 
if (!answer){ 
alert("Bye Bye Douchey!");
history.go(-1); } 
else{ alert("Thanks for sticking around!") } } 
document.writeln(confirmation()) //This will make the popup come up when page is loaded (So disable if  you want to call it like I have) //--> 
</script>

Code for Confirm button:

1
<form> <input type="button" value="Confirm button" onclick="return confirmation();"> </form>

Check if name is correct, if not bye bye!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<script type="text/javascript"> 
<!-- 
function testname(){ 
var name = prompt("Please enter your first name: (Remember it is case sensitive)","Stephen"); 
if (name == "Fred" || name == "Suzi" || name == "Crafty" || name == "Stephanie" || name == "Cindy"){
alert("Welcome to Tom's Blog " +name); 
if (name == "Thomas"){ 
window.location.href="http://www.thomasnorberg.com/wp-login.php"; } 
} 
else { alert("Bye Bye Douchey!") 
window.location.href="http://www.google.com"; 
} 
} 
document.writeln(testname()) //This will make the popup come up when page is loaded (So disable if if you want to call it like I have)
//--> 
</script>

Code for Name prompt button:

1
2
3
<form action="">
<input type="button" value="Name Prompt" onclick="return testname();" />
</form>

GD Star Rating
loading...
GD Star Rating
loading...