delete blank lines in data from a text area

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
sanju
Forum Commoner
Posts: 65
Joined: Sat Jun 21, 2008 2:15 am
Location: Kochi, India

delete blank lines in data from a text area

Post by sanju »

Hi all,


I need a help for removing blank lines in the data form a text area in the form.How can i do that.


Regards
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: delete blank lines in data from a text area

Post by Benjamin »

Hi sanju, can you post your code please?
jothirajan
Forum Commoner
Posts: 69
Joined: Tue Jan 27, 2009 12:06 am

Re: delete blank lines in data from a text area

Post by jothirajan »

sanju wrote:Hi all,


I need a help for removing blank lines in the data form a text area in the form.How can i do that.


Regards

document.getElementById('youtext_area_id').value.replace(/\s*$/g, '');

Replace the highlighted part with the setup you want to have
User avatar
sanju
Forum Commoner
Posts: 65
Joined: Sat Jun 21, 2008 2:15 am
Location: Kochi, India

Re: delete blank lines in data from a text area

Post by sanju »

This is the form in which text area.
[ code = PHP]
<form name=setup action=<? echo $PHP_SELF ?> method=post onSubmit="return valform(this);" >

<textarea name=answers cols=40 rows=10>
</textarea>
<input type="Submit" name="write" value="update" class="button">
</form>


recieving as
$answers= $_post[answers]
I dont want blank lines to be in this $answers currently its happening when I enter lines in text area.. how should 9i remove them.
Last edited by sanju on Mon Mar 16, 2009 7:13 am, edited 1 time in total.
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: delete blank lines in data from a text area

Post by papa »

Code: Select all

 
 
$answers=  str_replace("\n", "", $_post[answers]);
 
 
 
User avatar
sanju
Forum Commoner
Posts: 65
Joined: Sat Jun 21, 2008 2:15 am
Location: Kochi, India

Re: delete blank lines in data from a text area

Post by sanju »

hi

$answers= str_replace("\n", "", $_post[answers]);

the problem with above code is I need to remove blank lines only and other lines as lines..
with above code all lines will become one..
How can i make that?
jothirajan
Forum Commoner
Posts: 69
Joined: Tue Jan 27, 2009 12:06 am

Re: delete blank lines in data from a text area

Post by jothirajan »

<form method="post" name=setup onSubmit="return valform(this);" >
<input type="text" id="IDtextarea">
<textarea name=answers id="answers" cols=40 rows=10>
</textarea>
<input type="Submit" name="write" value="update" class="button">
</form>

<script language="javascript">
function valform()
{
document.getElementById('IDtextarea').value=document.getElementById('answers').value.replace(/\s*$/g, '');
}

</script>
User avatar
sanju
Forum Commoner
Posts: 65
Joined: Sat Jun 21, 2008 2:15 am
Location: Kochi, India

Re: delete blank lines in data from a text area

Post by sanju »

I have tried the js also but not working for me..... :(
jothirajan
Forum Commoner
Posts: 69
Joined: Tue Jan 27, 2009 12:06 am

Re: delete blank lines in data from a text area

Post by jothirajan »

sanju wrote:I have tried the js also but not working for me..... :(

Yeah


<form method="post" name=setup onSubmit="return valform(this);" >
<input type="text" id="IDtextarea">
<textarea name=answers id="answers" cols=40 rows=10>
</textarea>
<input type="Submit" name="write" value="update" class="button">
</form>

<script language="javascript">
function valform()
{
document.getElementById('IDtextarea').value=document.getElementById('answers').value.replace(/\s*$/g, '');
}

==========================================
See in the above code i just validated the textarea(without having any space in between them),

>>> then i just assign the value to a hidden value
>>> Request the hidden name not the textarea name....

==========================================
Thanks
JOE ..... Get me if you want more to have........
Post Reply