change variable in javascript

T

tony wong

i use the following script (from textbook) to restrict 160 character in
Message_cont textbox.

how can i to change the number of character to 70 if any double bytes
character detected in the textbox. Thanks a lot.

tony

*********************************
var text1;
function checklength()
{
var txt;
txt=document.formsend.Message_cont.value;
n=txt.length;
if (n>160)
{
document.formsend.Message_cont.value=text1;
return;
}
text1=document.formsend.Message_cont.value;
}

*************detect double byte character****************
( /[\u0100-\uffff]/.test( document.formsend.Message_cont.value ) )
 
E

Evertjan.

tony wong wrote on 22 okt 2006 in comp.lang.javascript:
i use the following script (from textbook) to restrict 160 character
in Message_cont textbox.

how can i to change the number of character to 70 if any double bytes
character detected in the textbox. Thanks a lot.


var text1 = 'My text';

function checklength() {

var cont = document.forms['formsend'].elements['Message_cont'];
var dblB = /[\u0100-\uffff]/.test( cont.value );
var max = ( dblB ) ? 160 : 70;

if ( cont.value.length > max )
cont.value = text1
else
text1 = cont.value;

};
 
T

tony wong

Thanks a lot. Evertjan


Evertjan. said:
tony wong wrote on 22 okt 2006 in comp.lang.javascript:
i use the following script (from textbook) to restrict 160 character
in Message_cont textbox.

how can i to change the number of character to 70 if any double bytes
character detected in the textbox. Thanks a lot.


var text1 = 'My text';

function checklength() {

var cont = document.forms['formsend'].elements['Message_cont'];
var dblB = /[\u0100-\uffff]/.test( cont.value );
var max = ( dblB ) ? 160 : 70;

if ( cont.value.length > max )
cont.value = text1
else
text1 = cont.value;

};
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,241
Latest member
Lisa1997

Latest Threads

Top