Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 06-17-2008, 08:16 AM Textarea help
Novice Talker

Posts: 5
Trades: 0
Hi!

I've made some helping requests here in this forum, and I always get help from you guys. I'm counting on you this time too.

Here's the problem I need help with.

I have a textarea and I'm sending the data inside with a POST and get it on another page with .php as a string.

I need javascript to check how many lines there are and put a certain string (for example: "<br />" at the end of every line.

Is it possible to do this?

We can maybe use another hidden form element to store the data "textarea with the <br>s"...

So any help here would be much appreciated.

THANK YOU!

Last edited by hegerp; 06-17-2008 at 08:19 AM..
hegerp is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-17-2008, 03:23 PM Re: Textarea help
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
http://uk2.php.net/nl2br
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 06-18-2008, 06:49 PM Re: Textarea help
Novice Talker

Posts: 5
Trades: 0
Okay. I messed the first post up a little...

The main thing I want to do is to connect to a database and get the text data from there and then output the data with \n as a javascript alert box.

I made a little sample code and it does not work!

Can you please have a look at it for me?

Code:
<?php
// connect and get the data is fine
$textarea = "Hi!
My name is Bond.
James Bond!"; // This is the text
 
 
$text_separated = nl2br($textarea); // Do the trick you showed me!
$array = explode("<br />",$text_separated); // I make an array from the textarea divided the parts that need a line break
 
echo "<script type='text/javascript'>alert('"; // start of the javascript alert
 
foreach($array as $key => $value){
echo $value; // write the text
?>\n<?php // to show the line break
};
 
echo "')</script>"; //finishing the javascript
?>
The most hurting part is that if I change the $value into a random string it does fine!
hegerp is offline
Reply With Quote
View Public Profile
 
Old 06-18-2008, 06:52 PM Re: Textarea help
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
Javascript doesn't allow newlines in the text itself. Trim them off and you're fine:

PHP Code:
<?php
// connect and get the data is fine
$textarea "Hi!
My name is Bond.
James Bond!"
// This is the text


$text_separated nl2br($textarea); // Do the trick you showed me!
$array explode("<br />",$text_separated); // I make an array from the textarea divided the parts that need a line break

echo "<script type='text/javascript'>alert('"// start of the javascript alert

foreach($array as $key => $value){
echo 
trim($value); // write the text
?>\n<?php // to show the line break
};

echo 
"')</script>"//finishing the javascript
?>
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 06-18-2008, 09:48 PM Re: Textarea help
Novice Talker

Posts: 5
Trades: 0
Thank you very much it works perfectly!

Wonderful!
hegerp is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Textarea help
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.83475 seconds with 12 queries