/    Sign up×
Community /Pin to ProfileBookmark

Problem displaying a link on a textarea

Hello guys,

I have a problem displaying links on a text area. Precisely this link: [url]http://www.amazon.com/Building-iPhone-Apps-HTML-JavaScript/dp/0596805780/ref=sr_1_1?ie=UTF8&s=books&qid=1276205263&sr=1-1[/url]

I store that link on my database. When I retrieve it I print it in the following way:

[code=php]
echo” <script type=’text/javascript’>
document.getElementById(‘description’).innerHTML='”.$row[0][‘Description’].”‘;
</script>
“;
[/code]

The link is not displayed at all, the text area appears blank. I tried using htmlentities and htmlspecialchars but all this does is print it as html, so I can see it on the source code but not as actual text on the web page.

I’m guessing I need to escape some characters to get this working (I think it’s the ‘&’) but I don’t know if there is an easy way to do this.

Any ideas?

Thanks!

to post a comment
PHP

9 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJul 05.2010 — [code=php]
htmlspecialchars($row[0])
[/code]
Copy linkTweet thisAlerts:
@mavalos88authorJul 05.2010 — [code=php]
htmlspecialchars($row[0])
[/code]
[/QUOTE]


Thank you for your quick reply. Like I mentioned before, I used htmlspecialchars with no luck. Unless I'm using it wrong.

The way I used it is like so:

[code=php]
echo" <script type='text/javascript'>
document.getElementById('description').innerHTML='".htmlspecialchars($row[0]['Description'])."';
</script>
";
[/code]


Thanks
Copy linkTweet thisAlerts:
@NogDogJul 05.2010 — Sorry, I didn't see that. I don't think HTML allows for any other tags within a textarea. (It only allows "#PCDATA" text in the spec.)
Copy linkTweet thisAlerts:
@mavalos88authorJul 05.2010 — Oh I see.

Thank you so much for your time.
Copy linkTweet thisAlerts:
@mavalos88authorJul 05.2010 — Actually I think I haven't explained myself properly.

I want to display the link as plain text, not as an actual link (that I know is not possible). I can't even find a way to do that. Or is that also impossible to do within a textarea?

Thank you
Copy linkTweet thisAlerts:
@NogDogJul 05.2010 — Are you sure the JavaScript works? Maybe try it with a simple, hard-coded string to see if it puts it into the textarea or not?

PS: For that matter, does it really need to be done via JavaScript?
Copy linkTweet thisAlerts:
@mavalos88authorJul 06.2010 — Are you sure the JavaScript works? Maybe try it with a simple, hard-coded string to see if it puts it into the textarea or not?

PS: For that matter, does it really need to be done via JavaScript?[/QUOTE]


It does work. It breaks when there is html or php tags and now I noticed it breaks with certain links, presumably because of special characters it doesn't like.

I'm not sure if JavaScript is the problem here, but I can't think of a way to load php variable data to a textarea. Like I said the code works if there is just plain text.

Do you have any idea how the boxes in this forum work? When you click on edit data will be loaded on to them no matter what html code or whatever is on it. I'm not sure if its a text area or if it's a different type of control.
Copy linkTweet thisAlerts:
@criterion9Jul 06.2010 — Pretty simple to put your php content within a textarea:
[code=php]
<textarea><?php echo $yourVar;?></textarea>
[/code]
Copy linkTweet thisAlerts:
@sohguanhJul 06.2010 — Do you have any idea how the boxes in this forum work? When you click on edit data will be loaded on to them no matter what html code or whatever is on it. I'm not sure if its a text area or if it's a different type of control.[/QUOTE]

The answer is simple. It does not use angle bracket to do formatting. It opt to have square brackets for it's formatting. This is why when you have URL which has angle brackets it does not clash and can render properly. In fact if you notice all other formatting this forum say square brackets. If I'm not wrong these square brackets are called phpBB tags.

http://en.wikipedia.org/wiki/BBCode
×

Success!

Help @mavalos88 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.9,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...