2

Am working in HTML5 and PhoneGap. Currently am facing an issue ; I couldn't handle the GO button of Android softkeyboad. My Functionality is that; I have a Login button and when i enter password and click on the GO button of the keyboard it will be process the same function of Submit Button in my page. like in the Screen shot enter image description here

Is there any solution for this?? When Trying like my latest code event is working but jQUERY AJAX calling is not working. :(

.. HTML code ..

  <div data-role="page" id="page_login">
  <div data-role="header" id="header_login">
  <img src="images/loginheaderlogo.png" id="login_header_logo"><br/>
  <img src="images/loginheaderarrow.png" id="login_header_arrow">
  </div>
    <div data-role="content" id="content_login" class="max_width scrolling">
    <form onsubmit="userLogin()"> <!--form submit-->
    <div id="login_textbox_container">
    <span class="valid" id="username_valid"></span>
    <img src="images/loginusericon.png" id="login_text_icon">
    <label class="input">
    <span>Username</span>
    <input type="text" id="input_usersername">
    </label>
    </div>
    <div id="login_textbox_container"><span class="valid" id="password_valid"></span>
    <img src="images/loginpassicon.png" id="login_text_icon">
    <label class="input">
    <span>Password</span>
    <input type="number" id="input_password">
    </label>
    </div>
    <div style="text-align:center; margin-top:37px">
    <div class="main_button"  id="login_button">
    <div class="left"></div>
    <div class="center">LOGIN</div>
    <div class="right"></div>
    </div> 
    <input type="submit" value="Login" id="btnSubmit" data-role="none"/>                    
    </div>
    </form>
    </div>
    </div>         

.. JS code ..

    $("#login_button").on( 'click', function(event) {
    userLogin();
    });

.. Ajax Call ..

    function userLogin() {
  var varData = 'username='+$('#input_usersername').val()+'&password='+$('#input_password').val();
var Validation_result = UserLogin_Validation()
if(Validation_result == true) {
$(".pre_loader").show();
setTimeout (function(){
$.ajax({
    type: "POST",
    url: 'http://xxx.xx.net/authenticate.php',
    data: varData,
    dataType: "json",
    crossDomain: true,
    cache: false,
    async: false,
    success: function (data) {
        userToken=data.token;
        localStorage.removeItem("TOKEN");
        localStorage.setItem("TOKEN",userToken);
        if(userToken!=0)
        {
            var query=[$('#input_usersername').val(),$('#input_password').val(),userToken,timeStamp];

            obj.insertLogin(query);
        }
        else
        {
            alert('Invalid User')
            $(".pre_loader").hide();
        }
    },
    error: OnError
});
},1000);}
    }
ULLAS MOHAN.V
  • 1,521
  • 1
  • 19
  • 36
  • http://stackoverflow.com/questions/11394607/iphone-default-keyboard-go-button-action-not-working-with-phonegap – rynhe Nov 27 '13 at 13:12

2 Answers2

1

I assume the 'go' button only works for submitting forms.

I do not see a form in your html.

<form onsubmit="userLogin()">
    <label>username</label>
    <input type="text" name="username" />
    <label>password</label>
    <input type="password" name="password" />
    <input type="submit" value= "submit">submit my form</form>
</form>

Edit

I have a working example: http://jsbin.com/IgeHUdEz/edit I have stripped the HTML somewhat, but please note at how you should use labels with the for attribute.

HTML

<div data-role="page" id="page_login">
    <form id="loginform" name="login"> <!--form submit-->
        <label class="input" for="input_usersername">
            <span>Username</span>
        </label>
        <input type="text" id="input_usersername">
        <label class="input" for="input_password">
            <span>Password</span>
        </label>
        <input type="number" id="input_password">
        <div style="text-align:center; margin-top:37px">
            <div class="main_button"  id="login_button"> 
                <input type="submit" value="Login" id="btnSubmit" data-role="none"/>
            </div>
        </div>
    </form>                   
</div>

Javascript

$("#loginform").on( 'submit', function(event) {
  userLogin();
});

function userLogin() {
  alert($('#input_usersername').val() + " - " + $('#input_password').val());
}
Daniël Tulp
  • 1,745
  • 2
  • 22
  • 51
  • Hi.. have a doubt.. in Action what i want to given? my current function is userLogin() so how can i call that ? – ULLAS MOHAN.V Nov 27 '13 at 13:44
  • that was just a classic representation of a form, you can probably leave the action and method attributes out and use `
    ` see the link rynhe gave
    – Daniël Tulp Nov 27 '13 at 15:49
  • Hi @ Daniël Tulp : Here our Ajax calling is not working.. now when we click on GO button; its goes to the userLogin Function but jQuery ajax calling not working.. is there any solution ? – ULLAS MOHAN.V Nov 28 '13 at 05:46
  • have you read http://stackoverflow.com/questions/11394607/iphone-default-keyboard-go-button-action-not-working-with-phonegap ? if yes and you still can't work it out, please post your code (including js) in an edit – Daniël Tulp Nov 28 '13 at 09:02
  • Can u please check my latest code? i have updated my latest one ! – ULLAS MOHAN.V Nov 28 '13 at 09:36
  • Its working.. but When jQueryAjax calls cmes ; its fails. Page just refresh and Ajax calling is not done ! :( – ULLAS MOHAN.V Nov 28 '13 at 11:47
  • that sounds like a problem not related to your original question – Daniël Tulp Nov 28 '13 at 12:10
  • I had a problem with this until I spotted I needed type=submit not just type=button – Magnus Smith Feb 10 '14 at 16:36
1

For future readers, alternate answer if you don't want to use forms.

document.addEventListener('deviceready', function () {
    document.getElementById('pwd').addEventListener('keypress',CheckKeyPress);
};

CheckKeyPress = function(e)
{
    if (e.keyCode == 13)
    {
        userLogin(); 
    }
}
Aaron
  • 1,313
  • 16
  • 26