User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 426,015 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,675 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 411 | Replies: 1
Reply
Join Date: May 2006
Posts: 57
Reputation: kaushik259106 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
kaushik259106 kaushik259106 is offline Offline
Junior Poster in Training

Need Suggestion regarding Limiting text box size

  #1  
Aug 7th, 2008
Hi everyone,
I need some suggestion.
Actually i created a text box and wrote a java script to limit its character hold to 500 char. I made my related db column size to 508bytes(Oracle).
The functionality was working fine when i suddenly found a bug.

Say for example if i put 498char as normal char and last 2 as special character("", ~`) my db throws exception as the size is more than 508bytes. The reason behind is the size of special character being not same as normal character.

I thought of two ideas not sure how to proceed!.

Idea1: In my javascript where i check the number of character i will change it to check the total size of all character in bytes and keep it less than or equal to 500.
Problem: Is it really possible to get the byte size of character input in java script?

Idea2: In my java script i will modify the max size based on number of number of special character.
So something like this
MAX_SIZE = 500 - SPECIAL_CHARACTER * SPECIAL CHAR SIZE -1 or something similar.
Problem: Special character dont have fixed size i belive.. So how will i come to know whats the size of which character.

Any other approach are always invited..
Thanks for reading the post!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2008
Posts: 375
Reputation: langsor is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 34
langsor langsor is offline Offline
Posting Whiz

Re: Need Suggestion regarding Limiting text box size

  #2  
Aug 7th, 2008
javascript does provide an escape and unescape methods which might help with this problem.

If you know your encoding of special characters you can also go with Option 2 and make an array of characters looking up length (no small project).

Maybe something like detecting onchange events of your input field and += to the value of a hidden field while escaping that value ... then you could track the size of the total field data with the special characters escaped from the hidden field.

I'm just brain storming here. I don't know if this would actually work or not. But I think it could work. If the character encoding is different than the escaped character encoding you might be able to submit the hidden field to the database ... then unescape the characters after retrieving them from the database.

The only problem that might arise is that the escaped character also might have what is considered a special character '%' and then some digits for encoding, but at least this would be a standard special character which you could account for in your script.

<head>
<script type="text/javascript">
alert( escape( '#' ) );
</script>
</head>

Let me know if I'm not making any sense.

Good luck
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 1:16 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC