Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Free Format Text Entry

Status
Not open for further replies.

RebelFox

Programmer
Jun 16, 2002
62
GB
I want to be able to set a page up to accept
free format text and store it in a database.

I have achieved this by creating an asp page with a form
that includes a text area. The text area gives me two
problems.

1) How can I limit the number of characters a user
can enter into a textarea box? All I have managed to
do is limit the sie of the text area on the web page.
Users can type and scroll beyond the size of the
text area I defined.

2) I have named my text area so I can refer to it once the
form has been posted. The problem is that the
textarea name only stores the first work from the text
area. For example is I type "This should work!" in my
text area box, the asp that reads the textarea after the
form has been posted only holds the value "This".

The code for the text area is as follows:-

<TEXTAREA COLS=50 ROWS=4 NAME=&quot;mytext&quot;></TEXTAREA>

Perhaps I should instead set up a text field? This then leads to another problem in that a 200 character text field
is one long field instead of a text box with a set number of columns and a set width.

Thanks.
 
>> the asp that reads the textarea after the
>> form has been posted only holds the value &quot;This&quot;.

that cannot be correct there is something wrong with ur code.
-There are only 10 types of people in the world, those who understand binary and those who don't-

-pete
 
RebelFox,

The code you posted should grab the entire content of the text window just fine, including spaces, or pretty much whatever else the User typed in it. A textarea can handle lots and lots of characters, and I don't think you can set it to a limit. You can ask the User to limit their input, or inform them that you will limit their input to the first n characters.

If you want to pass on the first n characters to some other app, then you simply send a substring. So, that would be
Code:
  var FullValue=<DocName>.<FormName>.mytext.value;
  var TruncValue=FullValue.substring(0,n);

Or something like that.

Cheers,

Edward &quot;Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!&quot; -- inventor of the cat door
 
Hi Guys,

You can validate a textarea with JS to alert the user that the submission has exceeded the specified amount, but just be sure to put this amount next to the textarea so that the user doesnt expect it to accept a long string.

<script language=&quot;javascript&quot;>
<!--
function countit(cur) {
var error = &quot;&quot;;
var maxlength = 50;
if (cur.areaname.value.length > maxlength) {
error = &quot;Sorry, an error occured!\nYou are only allowed to enter a maximum of &quot; + maxlength + &quot; characters.&quot;;
}

if (error) {
alert(error);
return false;
} else {
alert(&quot;That was less than &quot; + maxlength + &quot; characters and would be submitted sucessfully.&quot;);
return false;
}
}
-->
</script>
Code:
<form onsubmit=&quot;return countit(this);&quot;>
<textarea name=&quot;areaname&quot; cols=&quot;40&quot; rows=&quot;20&quot;></textarea>
<input type=&quot;submit&quot; value=&quot;Validate&quot;>
</form>
It is also possible to just stop the textarea accepting any more characters after the limit has been reached, but this requires a different method.

Hope this helps Wullie


The pessimist complains about the wind. The optimist expects it to change.
The leader adjusts the sails. - John Maxwell
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top