Page 1 of 1

delete blank lines in data from a text area

Posted: Wed Jan 28, 2009 6:16 am
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

Re: delete blank lines in data from a text area

Posted: Wed Jan 28, 2009 6:17 am
by Benjamin
Hi sanju, can you post your code please?

Re: delete blank lines in data from a text area

Posted: Wed Jan 28, 2009 6:20 am
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

Re: delete blank lines in data from a text area

Posted: Wed Jan 28, 2009 6:26 am
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.

Re: delete blank lines in data from a text area

Posted: Wed Jan 28, 2009 6:29 am
by papa

Code: Select all

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

Re: delete blank lines in data from a text area

Posted: Wed Jan 28, 2009 6:33 am
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?

Re: delete blank lines in data from a text area

Posted: Wed Jan 28, 2009 6:37 am
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>

Re: delete blank lines in data from a text area

Posted: Wed Jan 28, 2009 6:41 am
by sanju
I have tried the js also but not working for me..... :(

Re: delete blank lines in data from a text area

Posted: Wed Jan 28, 2009 8:15 am
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........