hi,
i am taking 3 textboxes, first textbox is multiline in this Textbox user write message for sending mobiles,
and second textbox is display characters length in first Textbox ,
i take maxium characters for one message is 150. and if user write write morethan 150 characters that time message send 2 times.
and Third Textbox default text is "1".
my aim is if user enter morethan 150 chacters, means he enter 151 character this time textbox3 display "2" upto 300 characters it
dispaly 2, and again user enter text more than 300 characters, this time also Textchange is 301th character. similarly
i give 3rd textbox name is messagecount.
please tell me how to write this code in javascript. please give a logic / code.
Thanks.
Loading

Jaish MathewsRank #225 · 11K reputationPosted May 5, 2010, 1:29 AM EDT
Hope this will be helpful
JavaScript
function handleChange(ctrl) {
var length = ctrl.value.length;
var mesageCount = 1;
// var displayValue = new Number(150) - new Number(length)
var mesageCount = length <= 150 ? 1 : Math.ceil(length / 150);
$get("TextBox2").innerText = length.toString();
$get("TextBox3").innerText = mesageCount.toString();
}
aspx
<div>
<asp:TextBox ID="TextBox1" runat="server">asp:TextBox><br /><br />
<input id="TextBox2" type="text" /><br /><br />
<input id="TextBox3" type="text" /><br /><br />
div>
CodeBehind
if (!IsPostBack)
{
TextBox1.Attributes.Add("onpropertychange", "handleChange(this);");
}
NB: I used ScriptManager
ajay rajuRank #4,639 · 333 reputationPosted May 5, 2010, 2:03 AM EDT
Please once explain this line what is the use of 1 : .........
var mesageCount = length <= 150 ? 1 : Math.ceil(length / 150);
DRISHTY134 reputationPosted May 5, 2010, 2:25 AM EDT
if(length <= 150 )
{
1
}
else
{
Math.ceil(length / 150)
}
CrishRank #1,487 · 1.1K reputationPosted May 5, 2010, 2:44 AM EDT
check length of message then apply condition as per required.
thanks
Jaish MathewsRank #225 · 11K reputationPosted May 5, 2010, 9:22 PM EDT
But we need 1 in thins case. Thta's the logic.