1

I'm trying to call an Aweber form code inside of a function in the head of the document. I'm creating a simple link that, when clicked will open up an Aweber form. But it's not working. I'm using the document.write function and have no clue if it's right at all.

Here's the head section code:

<script type="text/javascript">
function aweber()
{
document.write("<script type="text/javascript"
src="http://forms.aweber.com/form/74/1378551674.js"><\/script>");
}
</script>

And here's what I'm including in my document. It's not working -- I think it's a silly syntax issue.

<a href="javascript:aweber()">Aweber Form</a>

3 Answers 3

4
document.write("<script type="text/javascript"
src="http://forms.aweber.com/form/74/1378551674.js"><\/script>");

Should be

document.write('<script type="text/javascript" src="http://forms.aweber.com/form/74/1378551674.js"><\/script>');

First, you can't put double quotes in a double quoted string:

// see how the syntax highlighting gets screwy here? that's clue #1
var str = "he said "hello""; // bad
var str = 'he said 'hello''; // bad

// Encapsulate with different quotes
var str = 'he said "hello"'; // good
var str = "he said 'hello'"; // good

// Or escape the quotes
var str = "he said \"hello\""; // good
var str = 'he said \'hello\''; // good

And second, JS strings cannot have line breaks in them. You have to manually insert them to avoid syntax errors:

// bad
var str = "a
b";

// good
var str = "a"+
          "b";

// good, if you really need a newline character
var str = "a\nb";
var str = "a\n"+
          "b";
Sign up to request clarification or add additional context in comments.

2 Comments

Alex, this did it. Now, instead of using a link to open the form - is there a way to just display the form on page load, by keeping header code the same? What would the code be in the document?
Al your JS snippet is put a script tag in your html. Why not simply put it the HTML yourself, without the document.write() at all.
1

The quotes around the attributes in in

document.write("<script type="text/javascript" src="http://forms.aweber.com/form/74/1378551674.js"><\/script>");

are not properly escaped. Change

"<script type="text/javascript" src="http://forms.aweber.com/form/74/1378551674.js"><\/script>"

to

"<script type=\"text/javascript\" src=\"http://forms.aweber.com/form/74/1378551674.js\"><\/script>"

Comments

1

All your aweber() function does is make the JavaScript file, 1378551674.js, available to your document. I'm not familiar with Aweber Forms, but I would imagine you have to actually call some function within that JavaScript file to do something?

1 Comment

Sadly, no you don't. The entire js file is basically a massive document.write() itself: forms.aweber.com/form/74/1378551674.js

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.