Page 1 of 1

textarea width problem

Posted: Fri Jul 18, 2003 9:09 am
by zuzupus
textarea problem
hi,

i got problem regarding table width of textarea field,as when i enter some long text in this field and submitt he form the width of table becomes to long let say if i type in 'this is the best forum site for any tutorials' and when i click save then in next line this text prints like this Text
_________________ Save
|_________________|
i type in textarea // 'this is the best forum site for any tutorials
and then clicks on save then this text in next line looks like this
this is the best forum site
for any tutorial

i want this text prints exactly the width of textarea
'this is the best forum
site for any tutorials

<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=1 width=100% name="rsTable" id=rsTable cols=12>
<th nowrap>Text</th>
<td align="center">
<textarea name="text" class="mybar" id="tar" cols="15" rows="1" onfocus="tarea();" onblur="tarea();" title=""></textarea>
</td>
<input type="button" value="Save" name="Save" >
<td align="center"><?= $line["text"] ?></td> //printing value of textarea usinh PHP
</table>
<script>
function tarea()
{
if(document.getElementById)
{
if(document.getElementById("tar").rows == 3)
{
document.getElementById("tar").rows = 1
a = document.getElementById("tar").value
if(a)
{
document.getElementById("tar").title = a
}
else
{
document.getElementById("tar").title = ''
}
}
else
{
document.getElementById("tar").rows = 3
document.getElementById("tar").title = ''
}
}
}
</script>
also visit http://server2.vitodesign.com/log.phtml so that anybody can see the long width of text i want to make it reduce exactly like text area.

thansk in advance

Posted: Fri Jul 18, 2003 10:45 am
by Stoker
Just wrap to the same width as your textarea..

$output = wordwrap($_POST['text'], 15);

Posted: Mon Jul 21, 2003 3:30 am
by zuzupus
Stoker wrote:Just wrap to the same width as your textarea..

< $output = wordwrap($_POST['text'], 15);
sorry actually im newbie in PHP as i used this piece of code but dotn no whether this is working or not,exactly where should i have to use this code ,is it correct way please let me know

<? while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { ?>
<?$output = wordwrap($_POST['text'], 15); ?>
<td align="center"><?= $output["text"] ?></td>

now if i enter some message in textarea it will take only first letter let say 'this is text' then it will take only t please where should i have to put this $output code to get in proper way

thanks in advance

Posted: Mon Jul 21, 2003 4:33 am
by twigletmac
You've assigned $output to the value of the wordwrapped text, therefore instead of:

Code: Select all

<td align="center"><?= $output["text"] ?></td>
you need

Code: Select all

<td align="center"><?= $output ?></td>
Mac

Posted: Mon Jul 21, 2003 5:16 am
by zuzupus
when i enter some text in this field then i cant see any output when submission of form.

i can tell u how the code works

Code: Select all

//when clcik on save button text value submit in table t_emp
if (isset($HTTP_POST_VARS["save"]))
        {
[color=red] //storing in variable and inserting
$text = $HTTP_POST_VARS["text"];    
$query = "INSERT INTO t_emp(text)values ('$text')";
 mysql_query($query) or die("Query failed: Insert new row");
}
//now this query stored in result
$query = "SELECT * FROM t_emp ";
  $result = mysql_query($query) or die("Query failed: Fetch all rows");
[/color]
//when user login  will get textearea in html form 
<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=1 width=100% name="rsTable" id=rsTable cols=12>  
<tr bgcolor="#cccccc">
     <th nowrap>Text</th>
 </tr>
<? if (!isset($HTTP_POST_VARS["Save"])) { ?>
<tr> 
<td  align="center">
[color=blue]
 <textarea name="text" class="mybar" id="tar" cols="15" rows="1" onfocus="tarea();" onblur="tarea();" title=""></textarea>
</td>
[/color]
<td  align="center">
<input type="button"  value="Save" name="Save" border="1" >
</td>
  </tr>
<? } ?> 
[color=green]  
//$line value is important to use    
<? while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { ?>
<?$output = wordwrap($_POST['text'], 15); ?> //wrap the text
 <tr bgcolor="#FACB84">
<td align="center"><?= $line['text'] ?></td>//but if i use <?=$output ?>
then i will loose output in form as  $line['text']  coming from database -                                                                                                
   </tr>
 <? } ?>
 </table>
//jscript for textarea

Code: Select all

function tarea()
  &#123;
if(document.getElementById)
     &#123;
           if(document.getElementById("tar").rows == 3)
             &#123;
                 document.getElementById("tar").rows = 1
                   a = document.getElementById("tar").value
              if(a)
              &#123;
                document.getElementById("tar").title =  a
                   &#125;
                 else
                       &#123;
                            document.getElementById("tar").title = ''
	                         &#125;
	                 &#125;
	                 else
	                 &#123;
	                         document.getElementById("tar").rows = 3
	                         document.getElementById("tar").title = ''
	                 &#125;
	         &#125;
	    &#125;
thanks for your understanding

Posted: Mon Jul 21, 2003 5:28 am
by twigletmac
Are you trying to wrap text coming from a database? In that case maybe you need to do something like this:

Code: Select all

<?php
 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    // you need to use the wordwrap() function on the text you are trying to
    // wrap - i.e. the information in the database 
    $output = wordwrap($line['text'], 15); 
?>
<tr bgcolor="#FACB84"> 
<td align="center"><?php echo $output; ?></td>
   </tr> 
<?php
}
 ?>
Mac

Posted: Mon Jul 21, 2003 6:00 am
by zuzupus
thanks alot! but when i type some long text inside textarea then i submit the form then the width of textarea goes on increasing still back to old post.
this is text= "The quick brown fox jumped over the lazy dog.";
$output = wordwrap($line['text'], 15);
<?echo $output;?>

then output in form
The quick brown fox jumped over the lazy dog no change in result
actually i want some thing like Example 2. wordwrap() example in link
http://www.php.net/manual/en/function.wordwrap.php
so i tried liek this still no change
$output = wordwrap($line['text'], 15, "\n", 1);
<?echo "$output\n";?>
still no effect,may be due to nowrap in all tables
<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=1 width=100% name="rsTable" id=rsTable cols=12>
<tr bgcolor="#FACB84">
<td nowrap align="center"><?= $line["datum"] ?></td>
<td nowrap align="center"><?= $line["von"] ?></td>
<td nowrap align="center"><?= $line["bis"] ?></td>
<td nowrap align="center"><?= $line["kunde"] ?></td>
<td nowrap align="center"><?= $line["projekt"] ?></td>
<td nowrap align="center"><?= $line["hvorgang"] ?></td>
<td nowrap align="center"><?= $line["uvorgang"] ?></td>
<td align="center"><?echo $output;?></td>
<td nowrap align="center"><?= $line["ist"] ?></td>
<td nowrap align="center"><?= $line["soll"] ?></td>
<td nowrap align="center"><?= $line["status"] ?></td>
</tr>
</table>
thanks in advacne

Posted: Tue Jul 22, 2003 8:18 am
by Stoker
Uhm, text inside texarea and html stuff is very different, a newline does not give you a linebreak in html, for that you need a <BR />

Not sure if I understand the logic of questions and things in this thread.. *confused*

Posted: Tue Jul 22, 2003 8:28 am
by zuzupus
absolutely right even i too confused :) yaa it works fine with
wordwrap($line['text'], 20,"<br />", 1);

thanks its appreciable