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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

syntax issue 2

Status
Not open for further replies.

skibascott

IS-IT--Management
Mar 18, 2004
82
US
I am using a javascript function to collapse iframes. Here is the function:

Code:
function visibility(obj, anchor) {
   	if (document.getElementById(obj).style.display != "") {
      document.getElementById(obj).style.display = "";
      anchor.innerHTML = '[-]';
   	}
   	else {
      document.getElementById(obj).style.display = "none";
      anchor.innerHTML = '[+]';
   	}
	}

The code I am using on one of the iframes, works fine. It is coded with plain html and javascript. Here it is:

Code:
<a href='javascript:void(0)' onclick='visibility("psheet", this);'>[+]</a>Process Sheet <%Response.Write SheetNum%>
<IFRAME style="display: none" id="psheet" SRC='file:\\server13a\apps\Process Sheets\tempsheets\<%Response.Write SheetNum & ".pdf"%>' WIDTH=100% HEIGHT=100%>
</IFRAME>

Now, the additional iframes that will not collapse are coded in an asp script with the response.write function. Here it is:

Code:
Response.Write "<a href='javascript:void(0)' onclick='visibility('QA" & x & "', this);'>[+] </a>Quality Alert " & Link & "<br>"
Response.Write "<IFRAME style='display: none' id='QA" & x & "' SRC='file:\\server13a\shared\QUALITY\qalerts\qatest\" & Link & ".htm' WIDTH=100% HEIGHT=100% BACKGROUND-COLOR=BLUE>"
Response.Write "</IFRAME>"

I am almost positive that the error is in the syntax of the onclick visibility function call. When I compare the source of the html output, the code for both of the iframes(the functional iframe as well as the non-functional iframe) is identical execept for the onclick function call. The one that works, uses single quotes to encapsulate the entire function and double-quotes around the first parameter of the function call. The iframe that will not collapse has single quotes around the function as well as the first parameter. I believe that is the problem. I just cannot figure out the syntax to correct this. When I try to use the double quotes around the first parameter of the function, I receive an expected end of statement error.
How do I code this function call to use double quotes instead of single?
 
Two double-quotes in a row in ASP (VB) indicate a literal double-quote, so in place of the single-quotes you don't want, put two consecutive double-quotes ("").
 
your code seems fine and your suspicions about what's going wrong seem to be correct.. to correct it you need to add some asp-->JS handling, either add in some replaces, or use this function i use:

Function Javafriendly(Junk)
Javafriendly = Replace(Replace(junk,"\","\\"),"'","\'")
End Function

then apply it to your output :

Response.Write "<a href='javascript:void(0)' onclick='visibility('QA" & JavaFriendly(x) & "', this);'>[+] </a>Quality Alert " & Link & "<br>"

now .. i'm not sure what _X_ really is if it's a db value or something you might want to Server.HTMLEncode it instead.
but in the function call above you will want to make the value of X "happy" for JS

[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
 
also need to note, the way your IFRAMEs are being built should be the same ..

either use something like (note the addition of the replace):
Response.Write "<IFRAME style='display: none' id='QA" & x & "' SRC='file:\\server13a\shared\QUALITY\qalerts\qatest\" & Replace(Link,"'","''") & ".htm' WIDTH=100% HEIGHT=100% BACKGROUND-COLOR=BLUE>"
Response.Write "</IFRAME>"

OR : ( note the quote changes, and HTMLEncode and i dont leave things to chance, all tag attribs should be quoted.)

Response.Write "<IFRAME style=""display: none"" id=""QA" & x & """ SRC=""file:\\server13a\shared\QUALITY\qalerts\qatest\" & Server.HTMLEncode(Link) & ".htm"" WIDTH=""100%"" HEIGHT=""100%"" BACKGROUND-COLOR=""BLUE"">"
Response.Write "</IFRAME>"


as for overhauling the javascript call :
Response.Write "<a href='javascript:void(0)' onclick='visibility('QA" & JavaFriendly(x) & "', this);'>[+] </a>Quality Alert " & Link & "<br>"

Needs
Response.Write "<a href=""javascript:void(0)"" onclick=""visibility('QA" & JavaFriendly(x) & "', this);"">[+] </a>Quality Alert " & Server.HTMLEncode(Link) & "<br>"

the single quotes encased in single quotes in the response you had would have caused it to break or to cause unterminated string constants etc.



[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
 
Well, I used the double quotes suggested by Genimuse because it was so easy and that fixed my prob. Thank you for the help.
I also thank you DreX for the advice. You showed me some things that will definitely be of value as I continue to learn this stuff.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top