Click here to Skip to main content
15,908,437 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,
I have script like this:
Collapse
XML
<script type="text/javascript">
        function count(txt)
       {
          var textchar='<%= TextBox2.MaxLength %>';
          var textbox=document.getElementById(txt);
          var lbl=document.getElementById('<%= Counlbl.ClientID %>');
          if(textbox.value.length>textchar)
          {
          textbox.value=textbox.value.substrung(0,textchar);
          }
          lbl.innerText=textchar-textbox.value.length+" Characters remaining..";
       }
   </script>

This script working in internet explore but not working in Mozilla Firefox and also i put max length as 120 characters it raises exception after crossing length

1.How can i prevent this exception
2.How can i make this script to work in Firefox.

Can any one please help me.

Thanks in Advance

[Edit - fixed PRE block]
Posted
Updated 10-Jul-11 18:33pm
v3
Comments
thatraja 10-Jul-11 15:31pm    
Always mention the error message :(
tulasiram3975 9-Apr-12 6:01am    
Am not using try catch thats why am not able show you what the exception is..

There are a couple of things to change:

1. "substrung" should be "substring"

2. use "innerHTML" instead of "innerText" to work in Firefox too.

You didn't say what the exception is, so this might not solve your actual problem.
 
Share this answer
 
Comments
tulasiram3975 10-Jul-11 15:31pm    
Thanks You Sir Solves The Problem
question 1: you can use try...catch... to prevent the exception
http://www.w3schools.com/js/js_try_catch.asp[^]

you also can seek redress at google
http://www.google.com/search?q=javascript+exception+handling[^]

question 2: you can use jquery lib in you script. It's an excellent js lib and cross brower.
http://jquery.com/[^]
 
Share this answer
 
v3
Comments
tulasiram3975 10-Jul-11 15:31pm    
Thank You....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900