Click here to Skip to main content
16,016,925 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I got this code over the internet with some seaching and I have been using it in my website in two seperate places. It works very well but when putting it into another place it just refuses to work and I can not see why. Can anyone please help me figure this out??

This is to make a button click on "enter" key press

My javascript code
JavaScript
<<pre lang="cs">script>
          $(document).ready(function () {
              $("#password2").keydown(function (e) {
                   setEnterValue(e);
               });
           });

           function setEnterValue(e) {
               var key = checkBrowser(e);
               if (key == 13) {
                   $("#btnLogin").click();
               }
           }
           function checkBrowser(e) {
               if (window.event)
                   key = window.event.keyCode;     //IE
               else
                   key = e.which;     //firefox
               return key;
           }
    </script></pre>

My html code

ASP.NET
<input type="password" placeholder="Password" name="password" id="password1" runat="server"/> 
<input type="password" placeholder="Confirm" name="password" id="password2" runat="server"/> 
<asp:Button ID="btnLogin" runat="server" Text="Change" OnClick="btnChange_Click" /> 
Posted

This is what I did to fix this problem:

I still used this javascript
JavaScript
<script>
    $(document).ready(function(){
        $("#password2").keypress(function (e) {
            setEnterValue(e);
        });
    });

    function setEnterValue(e) {
        var key = checkBrowser(e);
        if (key == 13) {
            $("#btnChanged").click();
        }
    }

    function checkBrowser(e) {
        if (window.event)
            key = window.event.keyCode;
        else
            key = e.which;
        return key;
    }
 </script>


but...

I put my button and my textbox inside of a
ASP.NET
<asp:panel runat="server" defaultbutton="btnChanged" xmlns:asp="#unknown">my button and text box </asp:panel>	



and set the DefaultButton to the id of my button

This problem had nothing to do with browsers that didnt have javascript activated, as other javascript code in my website worked on the browser at the same time that i tried to run this code.


I hope that this will help someone
 
Share this answer
 
On that Browser java script may Disable


go to the below link it will help you

Java script Enable or Disable on Browser
 
Share this answer
 
Comments
Member 10395722 6-Feb-14 7:43am    
Like I said, in another place in my code, that javascript works well, so I think javascript is not disabled
Salman622 7-Feb-14 7:41am    
you have not get it right what i have said you

browser on which your application is running on that browser javascript may be disable so please check the setting of that browser

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