Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Running javascript on a Pocket PC

Posted on 2005-05-04
27
Medium Priority
?
321 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:gleznov
  • 12
  • 8
  • 7
27 Comments
 
LVL 25

Accepted Solution

by:
archrajan earned 800 total points
ID: 13929861
javascript is just browser dependant

if the OS in the pocket pc supports javascript
it should work fine!
0
 
LVL 25

Expert Comment

by:archrajan
ID: 13929871
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
 

Author Comment

by:gleznov
ID: 13929940
Could you give me some actual code, such as a function and the function call, that I could use that in?

JP
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 25

Expert Comment

by:archrajan
ID: 13929963
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
 

Author Comment

by:gleznov
ID: 13930262
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
 
LVL 25

Expert Comment

by:archrajan
ID: 13930273
can u post the generated code??
0
 
LVL 13

Expert Comment

by:davidlars99
ID: 13930343
all latest Pocket PCs support javascript
http://www.pocketpcskins.com/jsadoce.html
0
 

Author Comment

by:gleznov
ID: 13930508
Was that the code you wanted Archrajan?

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

JP
0
 
LVL 25

Expert Comment

by:archrajan
ID: 13930580
no the code when u see it in the browser do a view->source and post that code
0
 
LVL 13

Expert Comment

by:davidlars99
ID: 13930644
gleznov, actualy I have a friend with same last name as your nick
0
 

Author Comment

by:gleznov
ID: 13934583
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
 
LVL 25

Expert Comment

by:archrajan
ID: 13935095
just after the </form>
have this code

<script>
document.Form1.txtContID.focus();
</script>
0
 

Author Comment

by:gleznov
ID: 13935513
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
 

Author Comment

by:gleznov
ID: 13935523
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
 
LVL 25

Expert Comment

by:archrajan
ID: 13935642
why its not seen on the view source??
am not sure...


try to add it just after that textbox
0
 

Author Comment

by:gleznov
ID: 13935794
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
 
LVL 13

Expert Comment

by:davidlars99
ID: 13936273
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
 
LVL 13

Assisted Solution

by:davidlars99
davidlars99 earned 800 total points
ID: 13936287
put this in Page_Load(...) event and try again, first start with Me.IsStartupScriptRegistered(...)
0
 

Author Comment

by:gleznov
ID: 13936536
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
 

Author Comment

by:gleznov
ID: 13936557
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
 

Author Comment

by:gleznov
ID: 13936576
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
 
LVL 13

Expert Comment

by:davidlars99
ID: 13937827
--> 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
 
LVL 13

Expert Comment

by:davidlars99
ID: 13938073
you can also do this when page loads, take a look

If txtContID.CanFocus Then
     txtContID.Focus()
End If
0
 
LVL 13

Expert Comment

by:davidlars99
ID: 13938090
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
 

Author Comment

by:gleznov
ID: 13939065
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
 
LVL 13

Expert Comment

by:davidlars99
ID: 13939205
-->  is this maybe for plain windows apps?

you're right, it's for Windows Mobile Apps
0
 

Author Comment

by:gleznov
ID: 14097573
I guess it's just not going to work.  Thanks for the help though!

JP
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question