Solved

Javascript Question

Posted on 2011-09-08
7
176 Views
Last Modified: 2012-05-12
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
0
Comment
Question by:ASPNET_8
  • 3
  • 3
7 Comments
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 36501496
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>
0
 
LVL 13

Expert Comment

by:ansudhindra
ID: 36501503
try with onKeyDown event...

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

0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 36501511
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>
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:ASPNET_8
ID: 36501554
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""
0
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 500 total points
ID: 36501570
Its wprking finr for me

try this

      <asp:TextBox id="TextBox1"       runat="server" onchange = " alphanumeric()"></asp:TextBox>


Javascript function


        <script type="text/javascript">
function alphanumeric()
{
      var numaric = document.getElementById("TextBox1").value ;
      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>
0
 

Author Comment

by:ASPNET_8
ID: 36501603
Its not working I have tried twice
0
 

Author Closing Comment

by:ASPNET_8
ID: 36901593
Good
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question