hi,
iam having an application in which i need to validate all the fileds present above a particular field when user clicks on any field present in a page.similar to this link
http://my.naukri.com/manager/createacc2.php?othersrcp=5424&wExp=N

is this possible using validator callout extender.
can we use javascript to achieve this functionality.
if thru javascript it is possible,can any one send me the code.

waiting for u r replies

Recommended Answers

All 8 Replies

Hi,

I can provide you the logic, that I think will work.

You need to create an 2d array holding the id's and type of all the elements on form.
then onclick event of any element call the function with the index number of that element.

function clicked(ind)

using for loop you can check if all the elements are validated before that index or not.

Hope this will help you.

Hi,

First, you need to try it yourself. you can show me your code and I can let you know, where you r going wrong. :)

>>>can we use javascript to achieve this functionality.

Yes thats usually client side validation but some of the text boxes will need to be validated on the server side such as checking for username availabality that can be done on the server

For user name u need to use the RangeValidator coz u need minimum range of 4 characters. RangeValdator have 3 properties to mention.. minimum, maximum and data type u can only do that on server side script validation.... the password needs CompareValidator which have 2 properties, FieldToCompare property and fieldToValidate property and maybe the ErrorMsg property which will tell the user that the passwords entered does not match and also that can be done on the server side script validation

let me take what I said about client side validation back coz as far as I know all those control on that form are rich server controls not html controls except for file field textbox and browse button to uplaod file, simple bcoz no rich server control support it so it is n will alwayz be html server control

this requires a lot of work and server connection and im quite sure ur not looking for that.... I think u need to tell ur Dani fellows what exactly u need to do cos the site u uploaded does not give any clear path to take on

hi,
basically iam a asp.net developer,i wan to ahcieve this functionality using javascript,this is the code i have used

in design side

<head runat="server">
    <title>Untitled Page</title>
    <script>
    function validataform(ctrl)
    {
           if(ctrl.value=="")
               {
                   var lbl=document.getElementById("lblerr");
                   lbl.style.visibility='visible';
                   ctrl.style.border="1px solid #ff0000";
                   var imgerror=document.getElementById("imgerror");
                   imgerror.style.display="block";
                   var imgarrow=document.getElementById("imdisp");
                   imgarrow.style.display="block";
                   var imgcorrect=document.getElementById("imgcorrect");
                   imgcorrect.style.display="none";
                }
          else
                {
                   var imgcorrect=document.getElementById("imgcorrect");
                   imgcorrect.style.display="block";
                   var lbl=document.getElementById("lblerr");
                   lbl.style.visibility='hidden';
                   ctrl.removeAttribute('style');
                   ctrl.parentNode.className ="";
                   var imgerror=document.getElementById("imgerror");
                   imgerror.style.display="none";
                   var imgarrow=document.getElementById("imdisp");
                   imgarrow.style.display="none";
                }
  }
    
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table>
    <tr>
    <td>
    <asp:Label ID="lblname" runat="server" Text="Name"></asp:Label>
    </td>
    <td>
    <table>
    <tr>
    <td> <asp:TextBox ID="txtname" runat="server" class=""></asp:TextBox></td>
    <td>  <asp:Image ID="imgcorrect" runat="server"  style="display:none" ImageUrl="~/EtgsImages/OnlineImgs/correct.gif" /><asp:Image ID="imgerror" runat="server" style="display:none" ImageUrl="~/EtgsImages/OnlineImgs/erroricon1.gif" /></td>
    </tr>
    </table>
 
    </td>
    </tr>
    <tr>
    <td>
    </td>
    <td>
    <table>
    <tr>
    <td> <asp:Image ID="imdisp" runat="server" style="display:none" ImageUrl="~/EtgsImages/OnlineImgs/error.gif" /></td>
    <td>  <asp:Label ID="lblerr" runat="server" Font-Bold="false"  ForeColor="red">Please enter username</asp:Label></td>
    </tr>
    </table>
  
    </td>
    </tr>
    <tr>
    <td colspan="2" align="center">
    <asp:Button ID="btnsubmit" runat="server" Text="Submit" />
    </td>
    </tr>
    </table>
    </div>
    </form>
</body>

in code

protected void Page_Load(object sender, EventArgs e)
    {
        txtname.Attributes.Add("onblur", "javascript:return validataform(this);");
        if (!Page.IsPostBack)
        {
            lblerr.Style.Add("visibility", "hidden");
        }
    }

is there a better method to achieve this functionality

My other query is

is there a possibility to validate the fields above a particular field on onblur event

Hi,

The code will look like this.

<script language=javascript>
     var arrmsg = new Array(3);
     for(j=0;j<3;j++)
     {
           arrmsg[j]="";
     }
     var arrelement = new Array(3);

     for(j=0;j<3;j++)
     {
         arrelement[j] = new Array(2);
      }
      arrelement[0][0] = txtfn;
      arrelement[0][1] = text;
      arrelement[0][0] = txtln;
      arrelement[0][1] = text;
      arrelement[0][0] = txtmn;
      arrelement[0][1] = text;      
</scirpt>


<input type=text name=txtfn id=txtfn onclick=clicked(0)>
<input type=text name=txtln id=txtln onclick=clicked(1)>
<input type=text name=txtmn id=txtmn onclick=clicked(2)>
function clicked(ind)
    {
            var flag=false;
            for(i=0;i<ind;i++)
            {
                     if(checkelement[i][1] == "text")
                     {
                          if(checkblank(arrelement[i][0])
                          {
                                arrmsg[i] = arrelement[i][0]+" can not be blank";
                                flag=true;
                           }
                      }
             }
     }

    function checkblank(field)
    {
           if(document.getElementById("+field+").value == "")
              return false;
           else
              return true;
    }

I think this will solve the problem.

Hi,
thanks for the code.U are missing some parts of code ,there is no checkelement function declared.Can you check that one for me

i think this is the right code

function clicked(ind)
    {
  
                  var arrmsg = new Array(3);

                                      for(j=0;j<3;j++)
                                          {   
                                               arrmsg[j]="";
                                           }
                 var arrelement = new Array(3);

                                       for(j=0;j<3;j++)
                                         {
                                              arrelement[j] = new Array(2);
                                         }
                    arrelement[0][0] = 'txtfn';
                    arrelement[0][1] = 'text';
                    arrelement[1][0] = 'txtln';
                    arrelement[1][1] = 'text';
                    arrelement[2][0] = 'txtmn';
                    arrelement[2][1] = 'text';
                 
            var flag=false;
            for(i=0;i<=ind;i++)
            {                 
                     if(arrelement[i][1] == "text")
                     { 
                          if(checkblank(arrelement[i][0]))
                          {  
                                arrmsg[i] = arrelement[i][0]+"can not be blank";
                                 alert(arrmsg[i]);
                                flag=true;
                          }
                      }
             }
     }

    function checkblank(field)
    { 
           if(document.getElementById(field).value == "")
                  
              return true;
           else
              return false;
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.