Formula and Javascript Syntax

I need help with embedding Javascript in Formula. I’ve been working on this one line of code for 1.5 days now reading posts and changing code around and am always ‘almost’ there but not quite right. The confirm box will pop-up but the agent doesn’t run and I just get the default database web page. Can someone please read the following code and assist me with what I’m doing wrong?

The code below is a column formula located in a view for a web application. The user should be able to click the word ‘Delete’ in the view which prompts a confirm javascript box and runs an agent which deletes the doc if the user clicks OK. Another part which isn’t shown below is that I need the program to reload the same view instead of loading the database default setting.

ddurl:=“/”+@WebDbName+“/(WebDeleteDraft)?OpenAgent&”+@Text(@DocumentUniqueID);

@If(Documentstatus=“Draft”;“[<a href ="" onclick=‘javascript: if (confirm("You have chosen to delete a Draft document. Click OK to continue or cancel to exit without saving.")){window.location.href=]+ddurl+[ }’>Delete]”;REPORTID)

Subject: Formula and Javascript Syntax

Can you try reposting that?

It’s not entirely clear what happened there, but a View->Source seems to show that you’ve ended and restarted the passthru HTML around the point where you’re adding the ddurl value. That part of the formula should probably have looked like this:

@If(DocumentStatus = “Draft”; “[” + “<a href="" onclick="if (confirm(‘You have chosen to delete a Draft document.\n Click OK to continue or cancel to exit without saving.’)){window.location.href=" +ddurl+ " }'>Delete]”; REPORTID)

Subject: RE: Formula and Javascript Syntax

Yes - I did stop the PassThru before the ddurl variable and start again after. However, I tried your way but still get the same results. Also, I see you added ‘\n’ to the dialog. I’m assuming that is for a new line, which I think would be nice. However, when I added to my code I’m getting a ‘n’ and the second sentence doesn’t start on the 2nd line either.

ddurl:=“/”+@WebDbName+“/(WebDeleteDraft)?OpenAgent&”+@Text(@DocumentUniqueID);

@If(Documentstatus=“Draft”;“[”+“<a href ="" onclick='javascript: if (confirm("You have chosen to delete a Draft document. Click OK to continue or cancel to exit without saving.")){window.location.href=]+ddurl+”[“+ }'>Delete]”;REPORTID)

Subject: RE: Formula and Javascript Syntax

Sorry, my bad – to get a "", you need to use two: “\”. And don’t stop the passthru or you’ll break the link. That’s why you’re going nowhere fast. You’ll need to add single quotes around ddurl in the javascript statement as well. But, most importantly, you’ll need to learn to use View->Source to take a look at what your formula is actually creating on the web page. 90% of your problems on the web will have to do with a discrepancy between the HTML you think you’re creating and the HTML that’s actually happening, and if you’re operating blind (no idea what the actual HTML looks like), then you’re only guessing at what the problem might be.

ddurl:=“/”+@WebDbName+“/(WebDeleteDraft)?OpenAgent&”+@Text(@DocumentUniqueID); @If(Documentstatus=“Draft”;“[”+“<a href ="" onclick="javascript: if (confirm(‘You have chosen to delete a Draft document.\nClick OK to continue or cancel to exit without saving.’)){window.location.href=‘" +ddurl+ "’}">Delete]”; REPORTID)