I am working on a CRM system that allows me to write custom HTML and JavaScript inside its interface, and I can reference CRM variables (such as current process status, date, etc) by using hash values #variable.variablename#. So I tried to write the following JavaScript but the problem is that no links will be displayed regardless of if any of the three variables exists or not:
<script type="text/javascript">
if ( #variable.1# != null) {
<div><a href="/Service1.svc/vf/img?imgid=5#variable.1#" >View Page</a></div> }
if ( #variable.2# != null) {
<div><a href="/Service1.svc/vf/img?imgid=5#variable.2#" >View Page</a></div>
}
if ( #variable.3# !=null) {
<div><a href="/Service1.svc/vf/img?imgid=5#variable.3#" >View Page</a></div>
}
</script>
What might be the problem ?
I would guest that the content of
#variable.1#(2 and 3) isn’t valid javascript. Maybe you need to enclose them in quotes, like"#variable.1#"Also, you need to
document.writethe html – you can’t just put it on a line and expect to appear.Also, consider using “View source” (Ctrl+U on Firefox) to see the actual Javascript, you’ve constructed.