Forum Moderators: open
<script type="text/javascript">
var d = <%=(Form.Fields.Item("Field1").Value)%>
if ((d.length==0 ¦¦ (d==Null))
{
document.write(" ")
}
else
{
document.write("<li><a href="page1.asp?<%= "ID=" + Form.Fields.Item("ID").Value %>" onclick="NewWindow(this.href,'newpage','600','500','yes', 'center');return false" onfocus="this.blur()">newpage</a></li>")
}
</script>
It would be easier for us if you posted the actual output of the server script - ie: the client-side code (or an example thereof), otherwise we're a little on the dark.
There is probably quoting needed for the value (else it arrives looking like a variable). Perhaps this will do:
var d = [blue]"[/blue]<%=(Form.Fields.Item("Field1").Value)%>[blue]"[/blue] Javascript is case-sensitive:
Null --> [blue]null[/blue] The nested quoting on the document.write statement is all messed up.
Start and end the statement with single quotes. Use double quotes for attributes then use \-escaped quotes (sgl or dbl for) for quoted arguments inside attribute values.
<script type="text/javascript">
var d = "<%=(Form.Fields.Item("Field1").Value)%>"
if ((d.length==0 ¦¦ (d==null))
{
document.write(' ')
}
else
{
document.write('<li><a href="page1.asp?<%= "ID=" + Form.Fields.Item(\"ID\").Value %>" onclick="NewWindow(this.href,\'newpage\',\'600\',\'500\',\'yes\', \'center\');return false" onfocus="this.blur()">newpage</a></li>')
}
</script>
The result page shows:
Microsoft JScript compilation error '800a03f6'
Invalid character
for (\"ID\")
If I change the \" with ", then the page is normal except that they don't show the <li></li> despite the condition is met (d!= null).
There is no need to escape the quoting on the ASP (as far as JS is concerned. Client-side Javascript will never see it).
if ((d.length==0 ¦¦ (d==null))
d won't be null. It will hopefully be "" or "something"
However, if it were ever null (for some reason), then the order of the conditions should be changed, since comparing null.length==0 may not be a good idea.
if ( d==null ¦¦ d.length==0) I've just noticed that you have a bracket imbalance in your condition, which will definitely cause an error.