/    Sign up×
Community /Pin to ProfileBookmark

Max charcters in textbox.

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

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@CharlesFeb 10.2003 — [font=monospace]<form action="someScript.pl">

<div>

<textarea rows="5" cols="15" onchange="this.value=this.value.substr(0,25)">

</textarea>

</div>

</form>

[/font][font=georgia]

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.[/font]
Copy linkTweet thisAlerts:
@twixy2kauthorFeb 10.2003 — 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
Copy linkTweet thisAlerts:
@CharlesFeb 10.2003 — [font=monospace]<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>[/font]
Copy linkTweet thisAlerts:
@twixy2kauthorFeb 10.2003 — <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
Copy linkTweet thisAlerts:
@CharlesFeb 10.2003 — [font=monospace]<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>[/font]
×

Success!

Help @twixy2k spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...