Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

javascript function and a bit of php?

Status
Not open for further replies.

sophielois

Technical User
Sep 8, 2005
66
GB
How can i enable a user to click a link which triggers an alert saying something like
"are you sure you want to do that"
then if the user clicks yes it continues to the url if the user clicks no it stays where it is.

been trying to play around with this
Code:
function checkCom(url) {
	if (confirm("Are you sure you want to do that")) {
		document.location = url;
	}
}

and

Code:
<? echo"<a href=\"'javascript:checkCom'/55731/can/can_complete.php?userid=$userid\">Mark as Complete</a>";?>

I have little JS knowledge so don't really know where to go from here?

plus im pretty sure my mark up is incorrect in the link code

Soph
 
just do something along these lines:

Code:
<a href="site.html" onclick="return confirm('are you sure?');">Click Me</a>

but it is important to note that if javascript is disabled, the site will be loaded without the confirmation. for this reason, it is best to check server-side, on site.html itself (in my example).



*cLFlaVA
----------------------------
[tt]I already made like infinity of those at scout camp...[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
I don't know anything about PHP, but your JavaScript function looks fine. Of course, you will get 'OK' and 'Cancel' buttons instead of 'Yes' and 'No' buttons. Is that one of your issues?

Dave


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
That's in the PHP (which I already disclaimed my knowledge of). The JavaScript I was refering to as looking fine was NOT that included in the PHP snippet, but the function itself.

I noticed the parenthesis problem (and, it looks like, maybe a concatenation and quote problem?) in the PHP, but I don't know how to format PHP code, so I didn't know if that was okay or not.

Dave


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
Thanks for your posts guys, I've sorted the parenthesis problem.

I love it


he'll need parentheses around his parameter...

she'll need parentheses around her parameter...

oooh it sounds rude when you replace he with she

;)
Soph
 
Thank you, Cory.

I said the JavaScript function was fine and it was.

The problem you pointed out was with the function call (which was missing the parentheses).

Do you want to take this outside? [swords]

Dave


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
Just ignore him dave, he's having a bit of pre-
star.gif
(300) depression.


(He's gonna be saying the same thing to me about my pre-
star.gif
(400) depression when he's left me behind in the dust)


-kaht

How much you wanna make a bet I can throw a football over them mountains?
sheepico.jpg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top