PDA

View Full Version : Are you sure? Popup



nicksalad
09-24-2007, 04:27 PM
Hello, i need something like this:

http://www.devilishmu.com/askingpopup.jpg

When you click on a link, it starts a function, instead of start it inmediatelly, i need a pop up window like that one to show up asking the user if he really want to proceed, if he press accept, it starts the function and closes the window, if he press cancel, it does nothing and closes the window.

Sorry about my bad english.

thetestingsite
09-24-2007, 04:33 PM
function makesure() {
if (confirm('Your message goes here. Continue?')) {
dosomething();
//or return true;
}
else {
return false;
}
}


Then call the function like so:



<a href="something.html" onclick="return makesure();">Some Text</a>

Twey
09-24-2007, 05:19 PM
Sorry about my bad english.It's quite good, actually.

nicksalad
09-24-2007, 09:01 PM
I can't seem to make it work, it doesn't show the pop up window, i will keep trying meanwhile.

Thanks bouth of you for your replies.

thetestingsite
09-24-2007, 09:10 PM
Do you have a link to your page, or even if you post the code you are trying to implement it in, we can take a look.

nicksalad
09-24-2007, 09:18 PM
Sorry, here's the code (i just created a blank page to test),

<?php

function makesure() {
if (confirm('Your message goes here. Continue?')) {
return true;
}
else {
return false;
}
}



echo '<a href="#" onclick="return makesure();">PopUp</a>';

?>

the link to my website is http://www.devilishmu.com/popup.php

thetestingsite
09-24-2007, 09:24 PM
Oh, sorry; but I should have been clearer. The code I posted above is a javascript function, not php. The way you would have to do it is like so:



<html>
<head>
<title>Whatever</title>
<script type="text/javascript">
function makesure() {
if (confirm('Your message goes here. Continue?')) {
return true;
}
else {
return false;
}
}
</script>
</head>
<body>
<a href="test.php" onclick="return makesure();">Go There</a>
</body>
</html>


Hope this helps.

nicksalad
09-24-2007, 09:30 PM
Oh, sorry; but I should have been clearer. The code I posted above is a javascript function, not php. The way you would have to do it is like so:



<html>
<head>
<title>Whatever</title>
<script type="text/javascript">
function makesure() {
if (confirm('Your message goes here. Continue?')) {
return true;
}
else {
return false;
}
}
</script>
</head>
<body>
<a href="test.php" onclick="return makesure();">Go There</a>
</body>
</html>


Hope this helps.

hehe, that would explain why when i searched on php.net for confirm() there wasn't any results :o

I will try now, thanks again.


EDIT: It works great, is there any way to change the title of the pop up? like WARNING or smth?

thetestingsite
09-24-2007, 09:37 PM
No, because it is part of the browser window and it is there for security purposes. The only way you could do something like that is by making a javascript function open a div that looks like that window. Other than that, sorry.

Hope this helps nonetheless.

nicksalad
09-24-2007, 09:47 PM
No, because it is part of the browser window and it is there for security purposes. The only way you could do something like that is by making a javascript function open a div that looks like that window. Other than that, sorry.

Hope this helps nonetheless.

Ok doesn't matter really, thanks you a lot. :)

Now, another thing, i might need to open a new thread...

Please check my registration form page (not agreement) http://www.devilishmu.com/?action=regme

Would be useless to add an image verification to the form?

thetestingsite
09-24-2007, 09:49 PM
Here are a few links to some tutorials and whatnot to show how to get a CAPTCHA on your form.

http://www.google.com/search?q=captcha+php&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a

Hope this helps.

nicksalad
10-01-2007, 09:53 PM
Hello, i need now to make a variable text, i mean, instead of create x number of functions for x number of messages, smth like this:

<script type="text/javascript">
function makesure() {
if (confirm('$message')) {
return true;
}
else {
return false;
}
}
</script>

instead of this:

<script type="text/javascript">
function makesure() {
if (confirm('Your message goes here. Continue?')) {
return true;
}
else {
return false;
}
}
</script>

where $message is a php var, i know this is wrong since is not working, i don't know how to make it with javascript, thanks.

thetestingsite
10-01-2007, 09:56 PM
Try this:



<script type="text/javascript">
function makesure(message) {
if (confirm(message)) {
return true;
}
else {
return false;
}
}
</script>


Then you can call the script like so:



<a href="something.php" onclick="return makesure('<?php echo $var; ?>');">Do Something</a>


Of course, edit to suit your needs. Hope this helps.

nicksalad
10-01-2007, 10:33 PM
Worked great, thank you :)