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

A string problem

Status
Not open for further replies.

nivini

Programmer
Mar 24, 2004
64
Hello all
I have this code:
Code:
response.write "<td class='photo'>"
response.write "<img src='../shows"&(rec("pic"))&"'width=100 height=75 border='0'"
response.write " onclick=window.open('../shows"& rec("pic")&"',,'width=50,height=50, toolbar=no')>"
response.write "</td>"

The rec("pic") is an image (jpg) file, which contains spaces, for example: 2005111Al Taj Mahal.jpg.
It works fine for the
Code:
response.write "<img src='../shows"&(rec("pic"))&"'width=100 height=75 border='0'"
but for the
Code:
response.write " onclick=window.open('../shows"& rec("pic")&"',,'width=50,height=50, toolbar=no')>"
I get an error. Unterminated string constant
In the view source of the html i can see:
onclick=window.open('..shows/20051111Al
What is wrong with the string???
HHHELP
nivini


 
you need surrounding double-quotes.

try:

Code:
response.write """ onclick=window.open('../shows"& rec("pic")&"',,'width=50,height=50, toolbar=no')"">"

*cLFlaVA
----------------------------
[tt]I already made like infinity of those at scout camp...[/tt]
beware of active imagination: [URL unfurl="true"]http://www.coryarthus.com/[/url]

BillyRayPreachersSonIsTheLeetestHax0rDude
[banghead]
 
Shouldnt it be:
Code:
response.write " onclick=[COLOR=red]""[/color]window.open('../shows"& rec("pic")&"',,'width=50,height=50, toolbar=no')"">"

So that the quotes surround the parameters for the onclick event?

nivini, since you do not have quotes for the javascript in the onclick event it thinks the command ends at the first space it sees like this:
onclick=window.open('..shows/20051111Al
That leaves the first " in the line unterminated, hence your error. And if it continued from that point it would think that the ' above was a comment mark and ignore the rest of the line.

Something like: onclick=run my function
breaks at the first space so you end up with onclick=run and then it thinks that my and function are separate tags.
To keep them together it must be: onclick="run my function".

And it thinks the rest of the line is another command, one

Paranoid? ME?? WHO WANTS TO KNOW????
 
Sorry, cLFlaVA, it didn't do the job.
Other solution will be most welcome
nivini
 
theniteowl
Many thanks for the reply,
But now i have another error:
Cannot use parentheses calling a sub.
so i tried to take of the parentheses, this way the page load fine , but when i trigger the onclick event a new error comes up: type mismatch
the paretheses must be there , isn't it?
What will be with this string?
please your help
nivini
 
where do you get this error? in the javascript or the ASP page. If its the ASP page then what line is it erroring on?


Tony
 
Thanks Tony
The same line:
and the debug view colors this:
onclick="window.open '../shows/20051111Piramides.jpg',,'width=50,height=50, toolbar=no'"
nivini
 
VBScript uses the parens differently and it thinks you are trying to make a function call with multiple parameters.

Perhaps you can replace the parens with their character references.
Try replacing ( with chr(40) OR &#40;
And replace > with chr(41) or &#41;

Do you have any VBScript subs or functions on the page?
It might help to make sure that those subs or functions exist further down the page than the javascript you are writing dynamically.


Paranoid? ME?? WHO WANTS TO KNOW????
 
Can you try this and see if it will work?

response.write "<td class='photo'>"
response.write "<img src='../shows"&(rec("pic"))&"' width=100 height=75 border='0' onclick=""window.open('../shows"""& rec("pic") & """',,'width=50,height=50, toolbar=no')"">"
response.write "</td>
 
Thank you all, I'm still in a problem.
Nor the chr(40) works or Kendel's.
do you have some other solutions?
I've tried some other variations on your replies, but none worked.
desperred nivini
 
What about subs and functions? Do you have any? Can you put them at the end of the page so the above code executes first?

Otherwise, try writing out your window.open function into a complete javascript function with script tags.
Then in your onclick change it to not use parens.
For instance, you create the javascript function called openMyWindow()

In your onclick do: onclick="openMyWindow"
if you have to pass parameters inside the onclick then do it either of these ways:
onclick="call openMyWindow(paren1,paren2)"
onclick="openMyWindow paren1,paren2"

If VBScript has already taken control as default scripting for the page then parens will get you into trouble as vbscript will be trying to interpret the javascript commands embeded on the page and will evaluate the parens differently. If you use the call command you can use the parens but you can skip call and just put the parameters in without parens in some cases also.


Paranoid? ME?? WHO WANTS TO KNOW????
 
Thank you all very much.
The problem was with the second parameter in the open function, so it should be
Code:
response.write " onclick=""window.open('..shows/& rec("pic")&"',NULL,width=50,height=50,toolbar=no');"">"
Again thank you all
nivini
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top