Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Javascript (https://www.askmehelpdesk.com/forumdisplay.php?f=452)
-   -   I cannot understand a part of javascript function saldot() (https://www.askmehelpdesk.com/showthread.php?t=616715)

  • Dec 3, 2011, 07:34 PM
    dendenny01
    I cannot understand a part of javascript function saldot()
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

    <html>
    <script language="javascript">

    /// Start of Pincode length Validation ///
    function pinlen()
    {
    var n;
    n=f1.t1.value;
    if(n.length<7)

    {
    f1.t1.value="";
    f1.t1.focus();
    return false;
    }
    return true;
    }

    /// Start of Pincode Character validaion ///
    function pinchar()
    {
    var n,i,ch;
    n=f1.t1.value;
    for (i=0;i<n.length;i )
    {
    ch=n.charAt(i);

    if(isNaN(ch)==true)
    {
    f1.t1.value="";
    f1.t1.focus();
    return false;
    break;
    }}
    return true;
    }

    ///Start of Salary Character ///
    function salchar()
    {
    var n,i,ch
    n=f1.t2.value;
    for(i=0;i<n.length;i )
    {
    ch=n.charAt(i);

    if(isNaN(ch)==true && ch!=".")
    {
    f1.t2.value="";
    f1.t2.focus();
    return false;
    break;
    }}
    return true;
    }
    ///Start of Salary dot ///
    function saldot()
    {
    var n,i;
    n=f1.t2.value;
    for (i=0;i<n.length;i )
    {
    ch=n.substring(i,i 1);
    if(ch==".")
    {
    cnt=n.substring(i,n.length);
    if(cnt.length>3)
    {f1.t2.value="";
    f1.t2.focus();
    return false;
    break;
    }}}
    return true;}
    //// Varification steps ////
    function chk()
    {
    if(!pinlen())
    alert ("pincode should not be less tha 6");
    else
    {
    if(!pinchar())
    alert ("not a character");
    else
    {
    if(!salchar())
    alert ("Salary contains invalid Character");
    else
    {
    if(!saldot())
    alert ("Salary contains only 2 digits after dot");
    else
    {
    alert("pincode 7 salary valid");
    }}}}}


    </script>

    <body>

    <form name="f1">
    <h1><center>Validation of Pincode & Salary</center></h1>

    Enter the pincode
    <input type="text" name="t1" maxlength="10"><p>

    Enter the salary
    <input type="text" name="t2" maxlength="10"><p>
    <input type="button" name="b1" value="click" onClick="chk()"><p>
    <!--
    {
    if(!pinlen())
    alert ("pincode should not be less tha 6");
    else









    ---->

    </body>
    </html>

  • All times are GMT -7. The time now is 01:37 PM.