Return a decimal from a asp.net textbox using client side javascript - Urgent

Hi..

I am having a as.net text box and a button.

What i need to do is as soon as the user enters an amount i need to validate whether it is
an integer or not and then if it is i need to return the integer in decimal places using a client
side javascript which i will pass to some other c# function.

For eg.

User inputs 2000 in text box. (ASPX page)

My javascript function will take this 2000, value return 2000.00 (in decimal places..i have written this function)

I will take this 2000.00 value and call some c# function.

Can anyone tell me how to do this using client side javascript with CODE .

Thanks in Advance.

-Anjan
AnjanSahaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RejojohnyCommented:
using javascript

if (!isNAN(document.form1.textbox1.value))
   alert('not an integer');

remember javascript is case sensitive ..
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AnjanSahaAuthor Commented:
can you tell me with entire code...

i also want the 2000 converted to 2000.00 and pass it to a function..


can u post the full code as i am new to this...
0
anilnairpkdCommented:
Hi AnjanSaha,
pls go to this link you can get all the functions needed to format numbers
http://www.eggheadcafe.com/articles/20031204.asp

Cheers!
Anil Nair
0
anilnairpkdCommented:
AnjanSaha,
http://www.eggheadcafe.com/articles/20031204.asp
if you are not able to get  above link
0
anilnairpkdCommented:
AnjanSaha,
tried copying the URL twice
but here goes the code

<script language=JavaScript>
 
function GetDecimalDelimiter(nCountryCode)
{

       var sRet='';

       switch (nCountryCode)
       {

            case 3:  
                           
                           sRet = '#';
                           break;
           
            case 2:  
                           
                           sRet = ',';
                           break;
            default:
                           sRet = '.';
                           break;
 
        }

      return sRet;

}

function GetCommaDelimiter(nCountryCode)
{

       var sRet='';

       switch (nCountryCode)
       {
           
            case 3:  
                           
                           sRet = '*';
                           break;
            case 2:  
                           
                           sRet = ',';
                           break;
            default:
                           sRet = ',';
                           break;
 
        }

      return sRet;

}

function FormatClean(num)
{
     var sVal='';
     var nVal = num.length;
     var sChar='';
     
   try
   {
       for(i=0;i<nVal;i++)
      {
         sChar = num.charAt(i);
         nChar = sChar.charCodeAt(0);
         if ((nChar >=48) && (nChar <=57))  { sVal += num.charAt(i);   }
      }
   }
    catch (exception) { AlertError("Format Clean",e); }
    return sVal;
}
 

function FormatCurrency(num,nCountryCode)
{      
        var sVal='';
        var minus='';
        var Decimal='';
        Decimal = GetDecimalDelimiter(nCountryCode);
        if (num.lastIndexOf("-") == 0) { minus='-'; }
        if (num.lastIndexOf(Decimal) < 0) { num = num + '00'; }
        num = FormatClean(num);
        sVal = minus + FormatDollar(num,GetCommaDelimiter(nCountryCode)) + GetDecimalDelimiter(nCountryCode) + FormatCents(num);
        return sVal;
}

function FormatNumber(num,nCountryCode)
{      
        var sVal='';
        var minus='';
        var CommaDelimiter='';

        try
       {

           CommaDelimiter = GetCommaDelimiter(nCountryCode);

           if (num.lastIndexOf("-") == 0) { minus='-'; }

           num = FormatClean(num);

           num = parseInt(num);

           var samount = new String(num);
             
           for (var i = 0; i < Math.floor((samount.length-(1+i))/3); i++)
          {
             samount = samount.substring(0,samount.length-(4*i+3)) + CommaDelimiter + samount.substring(samount.length-(4*i+3));
           }

        }
         catch (exception) { AlertError("Format Number",e); }
        return minus + samount;
}

function FormatCents(amount)
{
     var cents = '';

      try
      {
           amount = parseInt(amount);
           var samount = new String(amount);

           if (samount.length == 0) { return '00'; }
           if (samount.length == 1) { return '0' + samount; }
           if (samount.length == 2) { return samount; }
         
           cents =  samount.substring(samount.length -2,samount.length);
         
      }
      catch (exception) { AlertError("Format Cents",e); }
      return cents;
}

function FormatDollar(amount,CommaDelimiter)
{
   try
   {
 
        amount = parseInt(amount);

        var samount = new String(amount);

        if (samount.length < 3) { return 0; }  

        samount =  samount.substring(0,samount.length -2);
             
        for (var i = 0; i < Math.floor((samount.length-(1+i))/3); i++)
        {
           samount = samount.substring(0,samount.length-(4*i+3)) + CommaDelimiter + samount.substring(samount.length-(4*i+3));
         }

   }
    catch (exception) { AlertError("Format Comma",e); }
    return samount;
}

 function AlertError(MethodName,e)
 {
            if (e.description == null) { alert(MethodName + " Exception: " + e.message); }
            else {  alert(MethodName + " Exception: " + e.description); }
 }

</script>

on the blur event of the text box add the following lines "this.value=FormatCurrency(this.value,1);"
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.