Posted: April 28 2003 at 10:21 | IP Logged
|
|
|
Tony,
Im catching up on the board messages.
I don't really have any documentation on the embedding of quotes. It gets a little hairy when you have to mix Javascript code and PowerScript code. I'll give a try on some fast tips however:
1. PowerScript will recognize strings surrounded by both single or double quotes. If you want to embed a single quote within a string, surround the string with double quotes. If you want to embed a double quote within a string, surround the string with single quotes.
2. In PowerScript, you can also prefix a single or double quote with one or more ~ (tilde) characters to embed quotes. For example...if you wanted to surround a string with single quotes and embed a single quote, you could do it like this: 'This is an embedded single quote ~' in the middle of this string'.
3. In Javascript, strings are delimited by double quotes. The escape character for Javascript is the \ (backslash). If you need to embed a double quote within Javascript, prefix it with a \.
So in the above example...the Javascript is executed first within the browser. I want to set a Javascript variable to a string which contains a PowerScript formula. This PowerScript formula needs to contain a string which contains string. So...We delimit the Javascript string (the PowerScript formula) with double quotes. The first string in the PowerScript formula, we delimit with single quotes. We now have a string embedded within the PowerScript string. We delimit this one with double quotes because PowerScript allows you to place double quotes within single quotes. But...the problem we have now is that the Javascript will see the double quotes and think they are the Javascript delimiters. We fix this by escaping the double quotes with the Javascript escape character (the backslash). Javascript will now just treat the \" character as a normal embedded double quote. When Javascript is done with the string, the backslash will not be there.
Now, we could have done this several different ways. We could also have delimited the innermost string with a ~'. Javascript doesn't care...Javascript just needs to have any embedded double quotes escaped with the \. So we could have escaped the innermost PowerScript string with the Powerscript escape character ~. We could have also delimited the outer PowerScript string with double quotes escaped for Javascript. We could also delimit all the strings with just double quotes but would have to use both Javascript and PowerScript escape characters. I haven't tested it but the following should illustrate this: document.execsendkeys.sendkeys.value = "ph_rtne( ph_createtimedevent( 1, \"ph_tts(~\"" + val1 + "~\")\", " + val2 + "))";
Well I realize I probably said to much and made things about as clear as mud...but hopefully shedded a little light on the subject .
Dave.
|