Running javascript on a Pocket PC

Hi,

     I'm trying to use some javascript code to cause a textbox to receive focus at page load in a mobile web app I'm programming in VB.NET.  I found a little java virtual machine (Ewe) but it still doesn't seem to help.  Is a JVM what runs Javascript as well as java, or is javascript just browser-dependent?  Are there any plugins you know of for javascript on a mobile Pocket PC?  Or best of all, does anyone have any code, javascript or otherwise, that will force a textbox to receive focus (for barcode scanning) in a mobile web app?  VB.NET has no setfocus for mobile web apps.

JP
gleznovAsked:
Who is Participating?
 
archrajanCommented:
javascript is just browser dependant

if the OS in the pocket pc supports javascript
it should work fine!
0
 
archrajanCommented:
and for a textbox to gain focus

This is used:

document.formname.textboxname.focus();
where formname is the name of the form
and
textboxname is the name of the texbox

and u can call the function onload of ur body tag
0
 
gleznovAuthor Commented:
Could you give me some actual code, such as a function and the function call, that I could use that in?

JP
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

 
archrajanCommented:
okay see this page example

<HTML>
<HEAD>
<TITLE> New Document </TITLE>

</HEAD>

<BODY onload = "document.frm.txt.focus();">
<form name = "frm">

This will not have focus<input type = "text" name = "txt1">
This will  have focus   <input type = "text" name = "txt">

</form>

</BODY>
</HTML>
0
 
gleznovAuthor Commented:
Here's the whole HTML side of my code - I get squigglies under "onload" - what else could I need to do to make it understand?  If I click in a space before onload it gives me a popup with two options, which are "runat" and "xmlns", don't know if that's any help.

JP

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="Scan.aspx.vb" Inherits="PTS_Status.MobileWebForm1" %>
<%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>
<HEAD>
      <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
      <meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
      <meta content="http://schemas.microsoft.com/Mobile/Page" name="vs_targetSchema">
</HEAD>
<body Xmlns:mobile="http://schemas.microsoft.com/Mobile/WebForm"  onload = "document.Form1.txtContID.focus();">
      <mobile:form id="Form1" runat="server">
            <mobile:Label id="Label1" runat="server" Alignment="Center" Font-Bold="False" Font-Size="Normal">Container ID</mobile:Label>
            <mobile:TextBox id="txtContID" runat="server" Alignment="Center"></mobile:TextBox>
            <mobile:Command id="cmdStart" runat="server" Alignment="Center" BreakAfter="False">Start</mobile:Command>
            <mobile:Command id="cmdStop" runat="server" Alignment="Center" BreakAfter="False">Stop</mobile:Command>
            <mobile:Command id="cmdComplete" runat="server" Alignment="Center">Complete</mobile:Command>
            <mobile:Label id="lblLines" runat="server" Alignment="Center">====================</mobile:Label>
            <mobile:Label id="lblStop" runat="server" Alignment="Center">Please Select Reason for Stop:</mobile:Label>
            <mobile:SelectionList id="cmbStop" runat="server" Alignment="Center"></mobile:SelectionList>
            <mobile:Command id="cmdOK" runat="server" Alignment="Center">OK</mobile:Command>
      </mobile:form>
</body>
0
 
archrajanCommented:
can u post the generated code??
0
 
davidlars99Commented:
all latest Pocket PCs support javascript
http://www.pocketpcskins.com/jsadoce.html
0
 
gleznovAuthor Commented:
Was that the code you wanted Archrajan?

David - I keep telling my pocket PC that, but it's just stubborn I guess.

JP
0
 
archrajanCommented:
no the code when u see it in the browser do a view->source and post that code
0
 
davidlars99Commented:
gleznov, actualy I have a friend with same last name as your nick
0
 
gleznovAuthor Commented:
Hmmm, I see that the onload in the body didn't make it into the code - any ideas how I can force it even though for some reason Visual Studios.NET 2003 doesn't recognize it as valid?

JP

<html><body>
<form id="Form1" name="Form1" method="post" action="scan.aspx?__ufps=981252">
<input type="hidden" name="__VIEWSTATE" value="aDxfX1A7QDw74Lic4q+x46a04KOILDA7Pjs+QQK1W8hj1BsLNOwQ5wLaZ7fVf/I=">
<input type="hidden" name="__EVENTTARGET" value="">
<input type="hidden" name="__EVENTARGUMENT" value="">
<script language=javascript><!--
function __doPostBack(target, argument){
  var theform = document.Form1
  theform.__EVENTTARGET.value = target
  theform.__EVENTARGUMENT.value = argument
  theform.submit()
}
// -->
</script>
<div align="Center">Container ID<br>
<input name="txtContID"/><br>
<input name="cmdStart" type="submit" value="Start"/><input name="cmdStop" type="submit" value="Stop"/><input name="cmdComplete" type="submit" value="Complete"/></div></form></body></html>
0
 
archrajanCommented:
just after the </form>
have this code

<script>
document.Form1.txtContID.focus();
</script>
0
 
gleznovAuthor Commented:
Here is the updated code - still doesn't work :(

JP

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="Scan.aspx.vb" Inherits="PTS_Status.MobileWebForm1" %>
<%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>
<HEAD>
      <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
      <meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
      <meta content="http://schemas.microsoft.com/Mobile/Page" name="vs_targetSchema">
</HEAD>
<body Xmlns:mobile="http://schemas.microsoft.com/Mobile/WebForm" onload="document.Form1.txtContID.focus();">
      <mobile:form id="Form1" runat="server">
            <mobile:Label id="Label1" runat="server" Alignment="Center" Font-Bold="False" Font-Size="Normal">Container ID</mobile:Label>
            <mobile:TextBox id="txtContID" runat="server" Alignment="Center"></mobile:TextBox>
            <mobile:Command id="cmdStart" runat="server" Alignment="Center" BreakAfter="False">Start</mobile:Command>
            <mobile:Command id="cmdStop" runat="server" Alignment="Center" BreakAfter="False">Stop</mobile:Command>
            <mobile:Command id="cmdComplete" runat="server" Alignment="Center">Complete</mobile:Command>
            <mobile:Label id="lblInfo" runat="server" Alignment="Center" ForeColor="Red"></mobile:Label>
            <mobile:Label id="lblLines" runat="server" Alignment="Center">====================</mobile:Label>
            <mobile:Label id="lblStop" runat="server" Alignment="Center">Please Select Reason for Stop:</mobile:Label>
            <mobile:SelectionList id="cmbStop" runat="server" Alignment="Center"></mobile:SelectionList>
            <mobile:Command id="cmdOK" runat="server" Alignment="Center" BreakAfter="False">OK</mobile:Command>
            <mobile:Command id="cmdCancel" runat="server" Alignment="Center">Cancel</mobile:Command>
            <mobile:Label id="lblInfo2" runat="server" Alignment="Center" ForeColor="Red"></mobile:Label>
      </mobile:form>
      <script>document.Form1.txtContID.focus();</script>
</body>
0
 
gleznovAuthor Commented:
And the Source:

<html><body>
<form id="Form1" name="Form1" method="post" action="scan.aspx?__ufps=459929">
<input type="hidden" name="__VIEWSTATE" value="aDxfX1A7QDw76rO37p+a46eC4KOILDE7Pjs+x82y/8ma5nHp9D4y0dKnYKgUp1Q=">
<input type="hidden" name="__EVENTTARGET" value="">
<input type="hidden" name="__EVENTARGUMENT" value="">
<script language=javascript><!--
function __doPostBack(target, argument){
  var theform = document.Form1
  theform.__EVENTTARGET.value = target
  theform.__EVENTARGUMENT.value = argument
  theform.submit()
}
// -->
</script>
<div align="Center">Container ID<br>
<input name="txtContID"/><br>
<input name="cmdStart" type="submit" value="Start"/><input name="cmdStop" type="submit" value="Stop"/><input name="cmdComplete" type="submit" value="Complete"/></div><br>
</form></body></htm
0
 
archrajanCommented:
why its not seen on the view source??
am not sure...


try to add it just after that textbox
0
 
gleznovAuthor Commented:
I tried that, (below), and what happens is now below the textbox and before the buttons, I get the text:
document.form1.txtcontID.focus();

so I'm guessing <script></script> within the body just isn't recognized?

JP

<body Xmlns:mobile="http://schemas.microsoft.com/Mobile/WebForm" onload="document.Form1.txtContID.focus();">
      <mobile:form id="Form1" runat="server">
            <mobile:Label id="Label1" runat="server" Alignment="Center" Font-Bold="False" Font-Size="Normal">Container ID</mobile:Label>
            <mobile:TextBox id="txtContID" runat="server" Alignment="Center"></mobile:TextBox>
            <script>document.Form1.txtContID.focus();</script>
            <mobile:Command id="cmdStart" runat="server" Alignment="Center" BreakAfter="False">Start</mobile:Command>
            <mobile:Command id="cmdStop" runat="server" Alignment="Center" BreakAfter="False">Stop</mobile:Command>
            <mobile:Command id="cmdComplete" runat="server" Alignment="Center">Complete</mobile:Command>
            <mobile:Label id="lblInfo" runat="server" Alignment="Center" ForeColor="Red"></mobile:Label>
            <mobile:Label id="lblLines" runat="server" Alignment="Center">====================</mobile:Label>
            <mobile:Label id="lblStop" runat="server" Alignment="Center">Please Select Reason for Stop:</mobile:Label>
            <mobile:SelectionList id="cmbStop" runat="server" Alignment="Center"></mobile:SelectionList>
            <mobile:Command id="cmdOK" runat="server" Alignment="Center" BreakAfter="False">OK</mobile:Command>
            <mobile:Command id="cmdCancel" runat="server" Alignment="Center">Cancel</mobile:Command>
            <mobile:Label id="lblInfo2" runat="server" Alignment="Center" ForeColor="Red"></mobile:Label>
      </mobile:form>
      <script>document.Form1.txtContID.focus();</script>
</body>
0
 
davidlars99Commented:
you have to use RegisterClientScriptBlock or RegisterStartupScript
like so


Dim script As String = "<script language=Javascript>" & _
                                 "function setFocus(){" & _
                                         "document.Form1.txtContID.focus();"  & _
                                 "}"  & _
                                 "</script>"


If(Not Me.IsStartupScriptRegistered("myScript"))
     Me.RegisterStartupScript("myScript", script)
End If

OR

If(Not Me.IsClientScriptBlockRegistered("myScript"))
     Me.RegisterClientScriptBlock("myScript", script)
End If


and then in the body tag


<body onload="setFocus()">
0
 
davidlars99Commented:
put this in Page_Load(...) event and try again, first start with Me.IsStartupScriptRegistered(...)
0
 
gleznovAuthor Commented:
I'm a little confused - first, should the "myScript" be the same as script (the string)?  Or should i tbe "setFocus"?

I'll give it a try as is right now though.

JP
0
 
gleznovAuthor Commented:
As is - no go.  Here's my page_load in full:

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        sqldataadapter1.Fill(DS_DC1)

        lblLines.Visible = False
        lblStop.Visible = False
        cmbStop.Visible = False
        cmdOK.Visible = False
        cmdCancel.Visible = False

        If Not (IsPostBack) Then
            Dim script As String = "<script language=Javascript>" & _
                                             "function setFocus(){" & _
                                                     "document.Form1.txtContID.focus();" & _
                                             "}" & _
                                             "</script>"


            If (Not Me.IsStartupScriptRegistered("myScript")) Then
                Me.RegisterStartupScript("myScript", script)
            End If


            cmbStop.Items.Add("-Select One-")
            For a As Integer = 0 To DS_DC1.Tables(0).Rows.Count - 1
                cmbStop.Items.Add(DS_DC1.Tables(0).Rows(a).Item("Description"))
            Next
            cmbStop.SelectedIndex = 0
        Else
            If lblInfo.Text <> "" Then lblInfo.Text = ""
        End If


    End Sub
0
 
gleznovAuthor Commented:
Did I do something wrong?  I take it now that "myScript" is a name you assign it, and when it doesn't find it, it registers the script string as "myScript".

JP
0
 
davidlars99Commented:
--> document.Form1.txtContID.focus();

when you access elements through the Form, txtContID must be the NAME of that element not the ID, try this instead

document.getElementById("txtContID").focus();


here's little debugging script for you, just point your mobile browser to it and you should see all the methods and properties for TextBox class, look for "focus" method and see if it's there

http://www.frozendev.com/domchecker2.htm
0
 
davidlars99Commented:
you can also do this when page loads, take a look

If txtContID.CanFocus Then
     txtContID.Focus()
End If
0
 
davidlars99Commented:
the following was copied from MSDN Documentation

Remarks:
The Focus method returns true if the control successfully received input focus. The control can have the input focus while not displaying any visual cues of having the focus. This behavior is primarily observed by the nonselectable controls listed below, or any controls derived from them.

A control can be selected and receive input focus if all the following are true: its ControlStyles.Selectable style bit is set to true, it is contained in another control, and all its parent controls are both visible and enabled.
0
 
gleznovAuthor Commented:
Results for your first of 3 responses:

I changed the code to the below, but still no focus:

        Dim script As String = "<script language=Javascript>" & _
                                         "function setFocus(){" & _
                                         "document.getElementById(""txtContID"").focus();" & _
                                         "}" & _
                                         "</script>"


        If (Not Me.IsStartupScriptRegistered("myScript")) Then
            Me.RegisterStartupScript("myScript", script)
        End If


Results for the second of 3:
I get squigglies under that - it doesn't recognize .canfocus or .focus in VB.NET for mobile web apps.

Results for 3 of 3:
There's no ControlStyles.selectable option that I can find - is this maybe for plain windows apps?

I feel like we're getting close, sorry this is such a hassle.

JP
0
 
davidlars99Commented:
-->  is this maybe for plain windows apps?

you're right, it's for Windows Mobile Apps
0
 
gleznovAuthor Commented:
I guess it's just not going to work.  Thanks for the help though!

JP
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.