Link to home
Start Free TrialLog in
Avatar of ASPNET_8
ASPNET_8

asked on

Javascript Question

How would i call a javascript function on the ontextchanged event of a text box in asp.net
and
what would be the javascript code to check the alphanumeric data

thanks
Avatar of Pratima
Pratima
Flag of India image

this will call javascript function on the ontextchanged event of a text box in asp.net



<asp:TextBox id="TextBox1" style="Z-INDEX: 101; LEFT: 136px; POSITION: absolute; TOP: 136px"
                        runat="server" onchange = " alert('test')"></asp:TextBox>
try with onKeyDown event...

<script type="text/javascript">
function callFunction() {
    //function code here....
}
</script>
like...
<input type="text" onKeyDown="javascript:callFunction()" />

For Alphanumaric


<asp:TextBox id="TextBox1" style="Z-INDEX: 101; LEFT: 136px; POSITION: absolute; TOP: 136px"
                        runat="server" onchange = " alphanumeric(this.value)"></asp:TextBox>


Javascript function


      <script type="text/javascript">
function alphanumeric(alphane)
{
      var numaric = alphane;
      for(var j=0; j<numaric.length; j++)
            {
              var alphaa = numaric.charAt(j);
              var hh = alphaa.charCodeAt(0);
              if((hh > 47 && hh<58) || (hh > 64 && hh<91) || (hh > 96 && hh<123))
              {
              }
            else      {
                         alert("Your Alpha Numeric Test Failed");
                   return false;
              }
             }
 alert("Your Alpha Numeric Test Passed");
 return true;
}
</script>
Avatar of ASPNET_8
ASPNET_8

ASKER

For Alphanumaric


<asp:TextBox id="TextBox1" style="Z-INDEX: 101; LEFT: 136px; POSITION: absolute; TOP: 136px"
                        runat="server" onchange = " alphanumeric(this.value)"></asp:TextBox>


Javascript function


      <script type="text/javascript">
function alphanumeric(alphane)
{
      var numaric = alphane;
      for(var j=0; j<numaric.length; j++)
            {
              var alphaa = numaric.charAt(j);
              var hh = alphaa.charCodeAt(0);
              if((hh > 47 && hh<58) || (hh > 64 && hh<91) || (hh > 96 && hh<123))
              {
              }
            else      {
                         alert("Your Alpha Numeric Test Failed");
                   return false;
              }
             }
 alert("Your Alpha Numeric Test Passed");
 return true;
}
</script>

this code is showing the error


""microsoft jscript runtime error object expected""
ASKER CERTIFIED SOLUTION
Avatar of Pratima
Pratima
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Its not working I have tried twice
Good