Getting control id within javascript
<p>I have created my own code to provide date masking and validation for TextBox control in asp.net. Below is the code. The code works perfectly.</p>

<p>function IsValidDate(ctrlID)
   {
        var validDate=true;</p>

<pre><code>    var myT=document.getElementById("ctl00_ContentPlaceHolder1_CandidateResume1_TabContainer1_TabPanel2_Education1_"+ctrlID);
    var mm=myT.value.substring(0,2);
    var dd=myT.value.substring(5,3);
    var yy=myT.value.substring(6);

    if(mm!=0 &amp;&amp; mm&gt;12){
        myT.value=""; validDate=false;
    }
    else
    {
        if((yy % 4 == 0 &amp;&amp; yy % 100 != 0) || yy % 400 == 0)
        {
            if(mm==2 &amp;&amp; dd&gt;29){
                myT.value=""; validDate=false;
            }
        }
        else
        {
            if(mm==2 &amp;&amp; dd&gt;28){
                myT.value=""; validDate=false;
            }
            else
            {
                if(dd!=0 &amp;&amp; dd&gt;31){
                    myT.value=""; validDate=false;
                }
                else
                {
                    if((mm==4 || mm==6 || mm==9 || mm==11) &amp;&amp; (dd!=0 &amp;&amp; dd&gt;30)){
                        myT.value="";  validDate=false;
                    }
                }
            }
        }
    }

    if(validDate==false)
    {
        myT.style.backgroundColor='#FF0000';
        myT.focus;
    }
    else
        myT.style.backgroundColor='#FFFFFF';
}

function maskDate(ctrlID)
{
    var myT=document.getElementById("ctl00_ContentPlaceHolder1_CandidateResume1_TabContainer1_TabPanel2_Education1_"+ctrlID);
    var KeyID = (window.event) ? window.event.keyCode : 0;        
    if((KeyID&gt;=48 &amp;&amp; KeyID&lt;=57) || KeyID==8)
    {
        if(KeyID==8)
            return;

        if(myT.value.length==2)
        {
            myT.value=myT.value+"/";
        }
        if(myT.value.length==5)
        {
            myT.value=myT.value+"/";            
        }
    }
    else
    {
        window.event.keyCode=0;
    }
</code></pre>

<h2>    }</h2>

<p>The problem -</p>

<p>I am attaching these functions to the textbox as -
TextBox1.Attributes.Add("onFocusout","IsValidDate('TextBox1');");
TextBox1.Attributes.Add("onKeyPress","maskDate('TextBox1');");</p>

<p>If you look at the javascript code I have collected the control id in myT variable. I have also passed the id of textbox while attaching the js functions using Attributes.Add()</p>

<p>My problem is that i dont want to pass the id of the textbox as i am already attaching it. That is i want to write the code as</p>

<p>TextBox1.Attributes.Add("onFocusout","IsValidDate();");
TextBox1.Attributes.Add("onKeyPress","maskDate();");</p>

<p>My question is how can i get the id of textbox to which i have attached these functions witin JS code.</p>

<p>NOTE: I DONT WANT TO PASS CONTROL NAME OR CONTROLS CLIENTID WHILE ADDING ATTRIBUTES. PLEASE NOTE THAT I WANT TO REPLACE</p>

<p>TextBox1.Attributes.Add("onFocusout","IsValidDate('TextBox1');");
WITH
TextBox1.Attributes.Add("onFocusout","IsValidDate();");
I WANT TO ATTACH THESE FUNCTIONS WITH MULTIPLE TEXTBOXES. </p>

<p>AS I AM USING .Attributes.Add(...) I WANT TO GET THE SAME CONTROLS CLIENTID WITHIN JS CODE.</p>

<p>Your help is highly appreciated.</p>

<p>Thanks and Regards
Mohammad Irfan</p>
