Showing posts with label strlink2. Show all posts
Showing posts with label strlink2. Show all posts

Monday, March 19, 2012

Formatting a Javascript string for SQL - Help please

I am well stuck in the mud right now.

Here is the problem. I am trying to write this: strLink2 = "<a href='JavaScript:OpenFile(" & strFileName & ")'>" & strFileName & "</a>" to SQL and then return it to a datagrid when I want it.

Easy enough, and as such all is well except for the fact that the Javascript doesn't work. In the grid it gets written as JavaScript:OpenFile(myfile). I need to add the single quotes around the file name so it writes JavaScript:Open('myfile').

I now know many ways that do not work. Any help would be greatly appreciated.Replace ' with two of them to cancel out.|||Thanks for the help, but it doesn't work. Atleast not in VStudio. Here is what does work right now:
strLink2 = "<a href='JavaScript:OpenFile(" & strFileName & ")'>" & strFileName & "</a>"

Before I put the string into SQL i need the strFileName. That works currently. But I need to add a ' to both sides of the strFileName in order for javascript to do it's thing when I pull this out of SQL and into a datagrid.

If I put (" & ' ' strFileName ' ' & ") the line is really just comjmented out.
note: the space between apotsrophes is for clarity here, there is no space when coding.

If you open up Visual Studio and paste this in and start adding ' you will see the problem.

Any ideas.|||Try ('" & strFileName & "')

Notice the single quotes are between the parentheses and the double quotes in each case.|||Thanks for your help.

Unfortunately the problem persists. While the string gets written to SQL the way I want. SQL sees the ' as an escape character and thus the resulting javascript comes out into the datagrid as: JavaScript:Open(

Instead of JavaScript:Open('myfile.xyz')

This is very frustrating. Is this so unusual a problem?|||Oops.. I should add that the solution worked...partly. So a big thanks for that.

The problem now is this.
I need to get rid of the ' that appear in the href. 'JavaScr... and )'>
strLink2 = "<a href='JavaScript:OpenFile(" & strFileName & ")'>" & strFileName & "</a>"

They need to be " instead of '.

Getitng closer