0

Simple question, however I can't find an answer anywhere.

I need a text input that can display HTML in it's value i.e:

<input type="text" name="guest_sc_player" id="guest_sc_player" size="27" value="<iframe width="100%" height="166" scrolling="no" frameborder="no" src="http://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F34196707&show_artwork=true"></iframe>" />
3
  • Why not use the iframe by itself? Commented Feb 23, 2012 at 23:20
  • Search Stack Overflow with "html wysiwyg". Commented Feb 23, 2012 at 23:22
  • I think you're looking for a textarea, not a text input. You'll need to html-encode your html too. Commented Feb 23, 2012 at 23:23

4 Answers 4

1

Most of the other answers will work for this specific situation, but the correct way to do this is to HTML Encode the entire value:

<input type="text" name="guest_sc_player" id="guest_sc_player" size="27" value="&lt;iframe width=&quot;100%&quot; height=&quot;166&quot; scrolling=&quot;no&quot; frameborder=&quot;no&quot; src=&quot;http://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F34196707&amp;show_artwork=true&quot;&gt;&lt;/iframe&gt;" />​​​​​​​​

jsfiddle

This avoids the necessity of worrying whether there may be single or double quotes in the value string. Depending on what platform you're using, there's probably a convenience method to do this automatically. e.g. HttpUtility.HtmlEncode in .NET

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

1 Comment

As I was using a PHP string I used htmlentities()
0
<input type="text" name="guest_sc_player" id="guest_sc_player" size="27" value='<iframe width="100%" height="166" scrolling="no" frameborder="no" src="http://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F34196707&show_artwork=true"></iframe>' />

single quotes work too.

Comments

0

Replace those double quotes within the value property with &quot;.

Comments

0

First, you need to encode all the characters that are required to be encoded.

Then, you can surround the string in single quotes.

<input type="text" name="guest_sc_player" id="guest_sc_player" size="27" value='&lt;iframe width="100%" height="166" scrolling="no" frameborder="no" src="http://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F34196707&amp;show_artwork=true"&gt;&lt;/iframe&gt;' />

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.