Click to See Complete Forum and Search --> : Max charcters in textbox.


twixy2k
02-10-2003, 06:38 AM
Hey, Is there a way to trim all the charcters in a textbox after a certain amount or after a certain character. To populate the textbox i have sessions inserting in the init. value. I want the max charcters to be 5. The normal

<input name="setname" type="text" class="insertshowsize" id="username" value="<%= Session("user") %><%= Session("svuser") %>" size="5" maxlength="5">

doesn't work.
It could be trimed onLoad, Submit etc.
Thanks
Alan
rar

Charles
02-10-2003, 07:05 AM
<form action="someScript.pl">
<div>
<textarea rows="5" cols="15" onchange="this.value=this.value.substr(0,25)">
</textarea>
</div>
</form>

That will clip entries in the field to 25 characters in length but it will fail for 12% of users. If this clipping thing is important then you will need to also do some server side form validation.

twixy2k
02-10-2003, 07:56 AM
The textbox it self is not going to be clicked in or edited. How do i name the text box then trim it from a onchange command in another text box, or submit button click. Possible?
Thanks

Charles
02-10-2003, 08:09 AM
<form action="someScript.pl" name="pharoh">
<div>
<textarea rows="15" cols="15" name="amenhotep4">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
</textarea>
</div>
<div>
<input type="text" size="4" onchange="if (/(\d+)/.test(this.value)) document.pharoh.amenhotep4.value = document.pharoh.amenhotep4.value.substr(0, RegExp.$1)">
</div>
</form>

twixy2k
02-10-2003, 08:51 AM
<form action="someScript.pl" name="form1" id="form1">
<div>
<input name="text" type="text" id="text" value="My Text Here" size="15">
</div>
<div> <input name="Button" type="button" value="Button">
</div>
</form>

Could a onclick be put on the button to trim the text to 5 charcters
Thanks Again

Charles
02-10-2003, 08:55 AM
<form action="someScript.pl" name="king">
<div>
<input name="tut" type="text" value="My Text Here" size="15">
</div>
<div> <input name="Button" type="button" value="Button" onclick="document.king.tut.value = document.king.tut.value.substr(0,5)">
</div>
</form>