Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set focus to input box and showing android keyboard using jquery mobile on pageshow

I am trying to set focus to the input box and showing android keyboard using jquery mobile on pageshow.

I tried a lot of options from web. but none is working as expected in both emulator and mobile.

Here is the Code:

<!DOCTYPE html>
<html>
    <head>
        <title>Title</title>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
    </head>
    <body>
        <div data-role="page" id="main">
            <div data-role="header"><h3>Set Focus, Show Keyboard</h3></div>
            <div data-role="content">
                <label for="gotoPage"></label>
                <input type="text" name="gotoPage" id="gotoPage" placeholder="Question No." data-mini="true"   />
            </div>
        </div>                              

        <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
        <script>
            $(document).on('pageinit',"[data-role=page]", function() {  

            });

            $(document).on('pagebeforeshow',"[data-role=page]", function() {                

            });

            $(document).on('pageshow',"[data-role=page]", function() {  
                $('#gotoPage').focus().select();                        
            }); 
        </script>
        <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>      
    </body>
</html>

Find the Screen shots for reference

enter image description here

enter image description here

Kindly advice... Thanks in advance...

NOTE:

As per Omar comment it is working fine in ios.... anyone can suggest how we get work this in android?

like image 777
Yesvinkumar Avatar asked Jun 04 '13 11:06

Yesvinkumar


1 Answers

The solution which works for me:

$("#main").on("pageshow" , function() {
$('#gotoPage').focus();
});
like image 193
Muath Avatar answered Sep 25 '22 09:09

Muath