Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q585 How do I dynamicaly change the number of rows and columns in a textarea on form submit?

You are here: irt.org | FAQ | DHTML | Q585 [ previous next ]

Only in Netscape Navigator 4 and Internet Explorer 4:

<html>
<head>

<script language="JavaScript"><!--
function createTextarea(rows,cols,text) {
    return '<form name="myForm">' +
           '<textarea name="myText" rows="' + rows + '" cols="' + cols + '">' +
           text +
           '<\/textarea>' +
           '<br>' +
           '<input type="button" value="Refresh" onClick="resizeTextarea()">' +
           '<\/form>';
}

function resizeTextarea() {
    if (document.all)
        text = document.all('myTable').document.myForm.myText.value;
    else if (document.layers)
        text = document.layers['myTable'].document.myForm.myText.value;
    else
        return;

    rows = 10; // default mimimum of 10
    cols = 10; // default mimimum of 10

    var textArray = text.split('\n');

    if (textArray.length > rows)
        rows = textArray.length;

    for (var i=0; i<rows; i++)
        if (textArray[i].length > cols)
            cols = textArray[i].length;

    if (document.all) {
        text = document.all('myTable').document.myForm.myText.value;
        document.all('myTable').innerHTML = createTextarea(rows,cols,text);
    }
    else if (document.layers) {
        text = document.layers['myTable'].document.myForm.myText.value;
        document.layers['myTable'].document.open();
        document.layers['myTable'].document.writeln(createTextarea(rows,cols,text));
        document.layers['myTable'].document.close();
    }
}
//--></script>

</head>

<body>

<span id="myTable" style="position:absolute">
<form name="myForm">
<textarea name="myText" rows="10" cols="10">
</textarea>
<br>
<input type="button" value="Refresh" onClick="resizeTextarea()">
</form>
</span>

</body>
</html>

Feedback on 'Q585 How do I dynamicaly change the number of rows and columns in a textarea on form submit?'

©2018 Martin Webb