2

i would like to get a resizeable textfield. You can see the Table and i have there a Input Text in HTML. The content depends on a calculation and i don't know how long the String would be. Is it possible to auto-resize the width of the input type "text" in a dependence to the represented content in the field?

Thanks for your help.

Here you can see my sample.

       <table class="returnTable" style="overflow: auto">
                <tr>
                    <td class="fett">Kalkulierter Hash-Wert:</td>
                </tr>
                <tr>
                    <td><input type="text" style="overflow: auto; resize: both" value="<?php if(isset($_POST['hashWert'])){echo $_POST['hashWert'];}  ?>"</td>
                </tr>
        </table>
Lukas Hieronimus Adler
  • 1,063
  • 1
  • 17
  • 44

2 Answers2

1

You can try:

PHP

$size = strlen($_POST['hashWert']);

HTML

<input type="text" size="<?php echo $size; ?>" value="<?php echo $_POST['hashWert']; ?>">

P.S. perhaps you have to adjust the size a little bit, according to your font-size etc.

empiric
  • 7,825
  • 7
  • 37
  • 48
0

You need to calculate width of the text. This looks promising: Calculate text width with JavaScript

when you know text width, you can set width of your :

var el = document.getElementById("MyInputText");
el.syle.width=width;

Don't forget to give your input proper ID so it can be found by javascript.

Community
  • 1
  • 1
Ján Stibila
  • 619
  • 3
  • 12