-1

I've looked around but couldn't find an answer to this.

How can I echo a script tag that has an src attribute? When I try this:

echo '<script type="text/javascript" src="script.js">document.writeln(3); 
</script>';

the code fails.

But when I do this and remove the src tag:

echo '<script type="text/javascript">document.writeln(3);</script>'

the code works.

what am I overlooking and how can I make the first version work?

0

2 Answers 2

4

You either include a src attribute, which references a file for the code or include the code directly in the script tag. You don't put both.

Sign up to request clarification or add additional context in comments.

Comments

1

It should actually be like this:

echo '<script type="text/javascript" src="script.js"></script>';
echo '<script type="text/javascript">document.writeln(3);</script>';

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.