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

Incorrect Syntax

Status
Not open for further replies.

Kris912

Programmer
Jul 29, 2005
27
US
Hi,

I am having trouble with the use of syntax in my ASP code. It is truncating the Title at the first blank space.

The code when it is not involved in a response.write is as follows:

<a href="javascript:ViewDetails('Project_details.asp?Title=<% = rs("Title") %>');" class="FormField">View</a>

when I put it in a response.write I am obviously putting the single or double quotes in the wrong place:

While Not rs.EOF
Title=rs("Title")
response.Write "<span class=fieldlabel><a href=javascript:ViewDetails('Project_details.asp?Title='" & title & "')" & "class=FormField>" & Title & "</a></span><br>"
counter = counter +1
rs.MoveNext
Response.Flush()
WEND

Combining the HTML and ASP syntax has always confused me. The logic I have no problem with but I seem to have a mental block when it comes to the syntax! I would appreciate any help you could lend me.

Thanks,
Kris912
 
Ok lets pretent the value of the Title field is "North Dakota" and that makes the output of your ASP logic:
[tt]
<a href=javascript:ViewDetails('Project_details.asp?Title='North Dakota'[highlight])c[/highlight]lass=FormField>[/tt]

It looks like there is a space missing between the call to the client-side function and the class attribute of your <a> tag.
 
try this:

Code:
response.Write "<span class=fieldlabel><a href=javascript:ViewDetails('Project_details.asp?Title=" & title &  "')" & "class=FormField>" & Title & "</a></span><br>"

-DNG
 
Oh, thats not the only problem I guess since the single quotes don't line up either:[tt]
<a href=javascript:ViewDetails([red]'[/red]Project_details.asp?Title=[red]'[/red]North Dakota[red]'[/red][highlight])c[/highlight]lass=FormField>[/tt]
 
Try using Server.URLEncode on the value of the Title field ... since it is used as a URL.
 
When I use this method:

Title=rs("Title")
sUrl = "javascript:ViewDetails('Project_details.asp?Title='" + Server.urlEncode(title) + "'"
response.Write(sUrl)

I am getting this response:

('Project_details.asp?Title='International+Paper+Blox+Cooling+Tower+and+Brine'javascript:ViewDetails

It is getting the entire title it looks like but it it treating the javascript as a literal.
 
Also, I tried what DotNetGnat suggested and it was still truncating the title.
 
Just to be clear.... somewhere in the code do you have something that looks something like this:
[tt]
<script>
function ViewDetails(MyURL)
{
// javascript to open another window goes here
}
</script>[/tt]

And you want to call that function when the <a> is clicked, is that right?
 
Yes, the function is in an include file. And the function works fine when it is used apart from ASP.

<a href="javascript:ViewDetails('Project_details.asp?Title=<% = rs("Title") %>');" class="FormField">View</a>

When it is is an <a> tag by itself it works like a charm.
 
I suspect that ultimately the <a> tag should look like this:
[tt]
<a href="javascript:ViewDetails([highlight]'[/highlight]Project_details.asp?Title=International+Paper+Blox+Cooling+Tower+and+Brine[highlight]'[/highlight])"[highlight] [/highlight]class="FormField">
[/tt]

Notice two things:
1) There are only two single quote characters... at the beginning and end value passed to the ViewDetails function.

2) There is a space between the javascript function and the class attribute.


Also the double quotes are not needed in my example above but I put them in to emphasize the beginning and ending of the values of the href and class attributes of the <a> tag.
 
That still a little unclear about what you are telling me.

response.Write "<span class=fieldlabel><a href=" & "javascript:ViewDetails(" & "'Project_details.asp?Title=" & title & "')" & " class=FormField>" & Title & "</a></span><br>"

When I break it apart further it is still only giving me the first word in the title. Therefore, the javascript is working or I would get an error. It just isn't encapsulatig the entire title. That's what is confusing me. The HTML segments have to be in double quotes. Also the entire Title is being written to the page correctly but the link it is creating (which should be the same) is what's being truncated. ???
 
try this:

Code:
response.Write "<span class=fieldlabel>
<a href=javascript:ViewDetails('Project_details.asp?Title= "&title&" ') class=FormField>" & Title & "</a></span><br>"

-DNG
 
It might help your syntax "mental block" mentioned above if you flip your train of thought around 180 degrees.

Forget ASP for a second and say to yourself:
"Self, if there was no ASP and I had to just type these pages out in raw HTML and JavaScript, what would I type?"

Once you can actually type something out that would work just fine on a static .HTM page then it becomes a lot easier to work backwards from there to make some ASP that works the way you like.
 
I tried it and it "really!!" doesn't work with those spaces. This is driving me crazy!! When I close up the spaces I'm back to the original problem. :(
 
Open the page in a browser.

Do "View Source" to show the HTML and JavaScript that was the output of your ASP.

Save it as a plain .HTM file on your desktop.

Hack at the problem code with Notepad or whatever program you use to edit HTML files. Save. Load in browser. Repeat if the problem still exists.

Only after it works do you go back and fiddle with your original ASP. It will be much easier to debug now that you have a working physical copy of the output you are trying to create with the ASP logic.

 
Sheco,

That's the point. I have typed it out in raw HTML and Javascript, and it works fine.

When I run the script and view the source code this is what is happening:

this code:

response.Write "<span class=fieldlabel><a href=" & "javascript:ViewDetails(" & "'Project_details.asp?Title=" & Title & "')" & " class=FormField>" & Title & "</a></span><br>"

Is producing this result:

<span class=fieldlabel><a href=javascript:ViewDetails('Project_details.asp?Title=Branch House')>Branch House</a></span>

Branch being the only word in the title being considered although it is showing up as the html and javascipt is supposed to be written and the entire Title is there encapsulated in the single quotes as it should be.

Do you have a solution for this?
 
I took another tact. I took the javascript out of the asp because it was syntactically impossible to make the titles links because the javascript needs the single brackets for it to work. So calling the script within a response.write was incompatible. I used the ASP to control the data and write it to the page but I took the link off the Title and put the link on an magnigying glass icon. Both in plain old HTML. Works like a charm! :) Thanks for all your help.
 
It's NOT "syntactically impossible", as you stated, and you were given a precise answer by Sheco. Since you didn't make sure the href value was enclosed by quotes with your VBScript ASP code, I suspect the problem was there. Any spaces in the value not enclosed in quotes would cause an error. You should enclose ALL the values for different attributes in quotation marks to avoid problems.

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top