0
<script type = "text/javascript">
function DisplayDashboard(Work Package)
{
var Src = '';

if (Work Package=='Google')
{
    Src =<a href="https://www.google.com">Link</a>;
}
else if(Work Package=='Bing') 
{
    Src = <a href ="https://www.bing.com">Link</a>;
}
    return <'+Work Package+'>;
}   
</script>

What I am trying to do is to look for Google or Bing and then display the correct link in Javascript. But for some reason it is not working.

1
  • What's your HTML code, and is this all of your JavaScript code? Commented Jun 5, 2013 at 5:47

3 Answers 3

1
  1. Variable name Work Package cannot have space between the characters
  2. string values must be surrounded bye '' or ""
  3. You need to return the value of Src

Try

function DisplayDashboard(WorkPackage) {
    var Src = '';

    if (WorkPackage == 'Google') {
        Src = '<a href="https://www.google.com">Link</a>';
    } else if (WorkPackage == 'Bing') {
        Src = '<a href ="https://www.bing.com">Link</a>';
    }
    return Src;
}
Sign up to request clarification or add additional context in comments.

Comments

0

replace Work Package with WorkPackage .Remove space.

function DisplayDashboard(WorkPackage)
{
var Src = '';

if (WorkPackage=='Google') 
    Src ='<a href="https://www.google.com">Link</a>';   
else if(WorkPackage=='Bing')    
    Src = '<a href ="https://www.bing.com">Link</a>';   
    return src;
}   

Comments

0

I guess you need to wrap HTML in double-quotes to form a valid string?

Such as:

Src = "<a href="https://www.google.com">Link</a>";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.