0

I am learning Javascript during my free time. As a part of a small project, I wanted to get users Youtube video ID, width and height using html form and then finally use those to write it in the below format.

For example, if user inputs width = 640, height = 360 and video id = IboGovrkfjE, the final output would be as below:

<iframe width="INPUT_WIDTH" height="INPUT_HEIGHT" src="http://www.youtube.com/embed/INPUT_VIDEOID?rel=0" frameborder="0" allowfullscreen></iframe>

When I used document.write as below it is not processed since 2 double quotes come together.

document.write "<iframe width="";

So, I used HTML ASCII " for double quotes

document.write "<iframe width=&#34;";

Now the problem is the ;

The ASCII for ; is &#59;

I am totally at a loss, don't know how to proceed, have been working on this for a week.

Sorry for not to the point question and any help or alternative in this regard would be greatly appreciated.

Thanks!

1

3 Answers 3

3

Either escape the doublequote:

document.write("<iframe width=\"");

or use different types of quotes:

document.write('<iframe width="');

or:

document.write("<iframe width='");

You also forgot the parentheses around the parameter list.

For the second problem, the solution is to use an entity code for the ampersand:

The ASCII for ; is &amp;#59;
Sign up to request clarification or add additional context in comments.

Comments

1

You can use sinqle quote instead:

document.write('<iframe width="');

or

document.write("<iframe width='");

Or escape the double quote:

document.write("<iframe width=\"");

Comments

0

Use single quotes or escape them.

var str = "<iframe src='foo'>";
var str = "<iframe src=\"foo\">";

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.