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

ahref and asp link prob 1

Status
Not open for further replies.

mthompo

Technical User
Jul 28, 2006
98
GB
hi,

have the following link to a page

Code:
<a href=<%Response.Write "custaddmot.asp?motdate=" & Server.URLEncode(motdate) & "&motid=" & Server.URLEncode(x_motid)%> target="_blank" onClick="
window.open(this.href, this.target, 'height=500,width=480,status=no,resizable=no,scrollbars=no');
return false;">FREE</a>

i want to add an if...then statement that lets page open link if hoursleft > 0 else a popup box that says there are no more hours left

so far...

Code:
<a href=<%if hoursleft > 0 then Response.Write "custaddmot.asp?motdate=" & Server.URLEncode(motdate) & "&motid=" & Server.URLEncode(x_motid)%> target="_blank" onClick="
window.open(this.href, this.target, 'height=500,width=480,status=no,resizable=no,scrollbars=no');
return false;"><%Response.Write "javascript:alert('No Hours Left');" End If %>FREE</a>

this brings up a vbscript error
please ay ideas welcome
 
Code:
<a href=<%if hoursleft > 0 then Response.Write "custaddmot.asp?motdate=" & Server.URLEncode(motdate) & "&motid=" & Server.URLEncode(x_motid)%> target="_blank" onClick="
window.open(this.href, this.target, 'height=500,width=480,status=no,resizable=no,scrollbars=no');
return false;"><%Else Response.Write "javascript:alert('No Hours Left');" End If %>FREE</a>

oops - sure it was there a minute ago
...now i get 'expected loop error' on line starting with
'Else'
 
i tried this as an example and it worked on my end with out any errors...

Code:
<html>
<body>
<%
hoursleft = 10
%>
<a href=<%
if hoursleft > 0 then 
Response.Write "custaddmot.asp?motdate=" & Server.URLEncode(motdate) & "&motid=" & Server.URLEncode(x_motid)%> 
			target="_blank" 
			onClick="window.open(this.href, this.target, 
					'height=500,width=480,status=no,resizable=no,scrollbars=no');
					return false;">
		<% Else 

		Response.Write "javascript:alert('No Hours left');"
		End If 
		%>
		FREE
</a>
<body>
<html>

-DNG
 
copied yours and works!
but all my 'Free' have disapeared?
 
what do you mean disappeared...can you do a response.write on your variable hoursleft and see what its value is...
also make sure that javascript is enabled...

-DNG
 
sorry css prob...
but now i get a java error 'unterminated string constant'?

Code:
<td class = mfitsml>
<a href=<%
if hoursleft > 0 then 
Response.Write "custaddmot.asp?motdate=" & Server.URLEncode(motdate) & "&motid=" & Server.URLEncode(x_motid)%> 
target="_blank" 
onClick="window.open(this.href, this.target, 
'height=500,width=480,status=no,resizable=no,scrollbars=no');
return false;">
<% Else 
Response.Write "javascript:alert('No Hours left');"
End If 
%>
<span class="mfitsml">FREE</span>
</a>
</td>
 
make sure that you have:

onClick="window.open(this.href, this.target,'height=500,width=480,status=no,resizable=no,scrollbars=no');return false;">

on a single line without any carriage returns or spaces...

-DNG
 
try this:

Code:
<html>
<body>
<%
hoursleft = 10
%>
<td class = mfitsml>
<a href=<%if hoursleft > 0 then 
Response.Write "custaddmot.asp?motdate=" & Server.URLEncode(motdate) & "&motid ="& Server.URLEncode(x_motid)%> 

target="_blank" onClick="window.open(this.href, 

this.target,'height=500,width=480,status=no,resizable=no,scrollbars=no');return false;">
<span class="mfitsml">FREE</span>
</a>
<% Else 
Response.Write "javascript:alert('No Hours left');"
End If 
%>
</td>
<body>
<html>

-DNG
 
double checked - but same error

Code:
        <td class = mfitsml>
		<a href=<%
		if hoursleft > 0 then 
Response.Write "custaddmot.asp?motdate=" & Server.URLEncode(motdate) & "&motid=" & Server.URLEncode(x_motid)%> 
target="_blank" onClick="window.open(this.href, this.target,'height=500,width=480,status=no,resizable=no,scrollbars=no');return false;">
<% Else 
Response.Write "javascript:alert('No Hours left');" 
End If %>
      <span class="mfitsml">FREE</span>
</a>
</td>
 
got it - many thanks - was missing quotes

Code:
<td class = mfitsml>
		<a href="<%
		if hoursleft > 0 then 
Response.Write "custaddmot.asp?motdate=" & Server.URLEncode(motdate) & "&motid=" & Server.URLEncode(x_motid)%> 
target="_blank" onClick="window.open(this.href, this.target,'height=500,width=480,status=no,resizable=no,scrollbars=no');return false;"
<% Else 
Response.Write "javascript:alert('No Hours left');" 
End If%>">
      <span class="mfitsml">FREE</span>
</a>
</td>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top