/    Sign up×
Community /Pin to ProfileBookmark

Limit textarea problems

I’ve got some javascript that limits the characters in a textarea. It works fine on the client side.

<script language=”javascript” type=”text/javascript”>
function limitText(limitField, limitCount, limitNum) {
if (limitField.value.length > limitNum) {
limitField.value = limitField.value.substring(0, limitNum);
} else {
limitCount.value = limitNum – limitField.value.length;
}
}
</script>
However, when I go to save to the database and use the return/enter key in my text, it throws an error.

Microsoft OLE DB Provider for SQL Server error ‘80040e21’

Can anyone help me with the return key, html its 1 character and saving to the database its 2, so I’m exceeding the nvarchar(1000). Any help would be appreciated.

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@KorAug 14.2007 — we need to see the whole picture, the HTML generated by your server side application, the event which triggers the function... and so on... Could be a server side problem, not a client side (javascript) one.
Copy linkTweet thisAlerts:
@ssaville24authorAug 14.2007 — <textarea name="comments" id="comments" rows="5" cols="60" wrap="on" onKeyDown="limitText(this.form.comments,this.form.countdown,1000);"onKeyUp="limitText(this.form.comments,this.form.countdown,1000);"><%if request_id <> "" then%><%=rs3("comments")%><%end if%></textarea>
Copy linkTweet thisAlerts:
@KorAug 14.2007 — That is [I]not[/I] the HTML generated, that is HTML/ASP genuine code. What do you see when you try a View source?

Anyway, in javascript the values of the form controls' [B]value[/B] attribute (same as any value attribute) return [I]strings[/I], not [I]numbers[/I], thus you better transform them ([B]Number()[/B] method is a good one) before compare them.
Copy linkTweet thisAlerts:
@Orc_ScorcherAug 14.2007 — function limitText(limitField, limitCount, limitNum) {
with (limitField.value.replace(/r?n/g, "rn")) if (length &gt; limitNum)
limitField.value = slice(0, limitNum).replace(/rn/g, "n")
else
limitCount.value = limitNum - length
}
But you should really fix your server-side code, too. If you're relying on your clients to send you only nice, acceptable data then you're living dangerously.
Copy linkTweet thisAlerts:
@ssaville24authorAug 21.2007 — This works fine for me, thank you.
×

Success!

Help @ssaville24 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 5.29,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...