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

Javascript within ASP apostrophe problem, little help?

Status
Not open for further replies.

JGKWORK

IS-IT--Management
Apr 1, 2003
342
0
0
GB
Hi,

I'm trying to use Javascript within ASP but I am receiving a "Syntax error" can someone please show me what's wrong with it? I suppose it must be something to do with the apostrophes: (its all written on one line).


<%if ShowButton = "True" then response.write "<input type='button' Onclick=Javascript:location.href=' value='Test' name='B1'>" end if %>

Many thanks!
 
Hmmm - your code actually worked for me...

It maybe that the ShowButton variable is a boolean rather than a string, i.e.

'boolean
ShowButton = True

is different to

'string
ShowButton = "True"

Also, not that it matters to the syntax, but you don't need the "end if" if you put an If statement all on one line.

HTH
Beck
 
I typically do not write everything on one line, but one of my co-workers does and when I have seen his code, he does not use the end if statement. For my own part, I usually break it up and put it on multiple lines. Not sure if this is the problem, per se, but might be another thought.

Another thought is apostrophes (as you suspect) in your onclick event. Try something like this:
Code:
<%if ShowButton = "True" then 
response.write "<input type='button' Onclick=""Javascript:location.href='[URL unfurl="true"]http://www.google.com'""[/URL] value='Test' name='B1'>" 
end if %>

------------------------------------------------------------------------------------------------------------------------
If you don't have a sense of humor, you probably don't have any sense at all.
- Anonymous
 
Try:

<%if ShowButton = "True" then response.write "<input type=""button"" Onclick=""location.href=' value=""Test"" name=""B1"">" end if %>
 
Chopstik is right, the end if is not needed.
 
Or you could use entities for the quotes instead:


<% if ShowButton = "True" then response.write "<input type='button' Onclick='Javascript:location.href=&quot; value='Test' name='B1'>" %>
 
Don't use the javascript: tag inside an event.

To avoid the kludges of VBScript's quotes within quotes:

<%if ShowButton = "True" then%>
<input type="button" onclick="location.href=' value="Test" name="B1">
<%end if %>
 
Many thanks all, I have removed the end if and used BeckD's suggestion, works great...

Thanks again to all....
 
No I didn't I used mbiro's suggestion! hehe.

Thanks...
 
I don't believe that "" is a kludge in VBScript. I believe the appropriate term is "escape character"...unless you also classify \\, \', \", etc as kludges...

Actually it was probably harder to implement "" as an escape character then it would be a \-based system since "" could be the whole string or simply an escape inside a string, etc. Or not, now that I think about it, a slash-based system is probably the same level of difficulty to implement, just a hundred times more useful.

-T

barcode_1.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top