Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Can you please provide me equivalent VBScript for this JavaScript ?

Posted on 2007-12-02
6
913 Views
Last Modified: 2008-02-01
<html>

      <head>
            
            <script language="javascript">
            
            function FuncKeyboard(e)
            {
                  var key;

                  if (window.event)
                  {
                        key = window.event.keyCode;
                  }
                  else
                  {
                        key = e.keyCode;
                  }

                  if (key == 13)
                  {
                        document.forms[0].submit();
                  }
            }

            window.onload = function()
            {
                  document.forms[0].elements["text2"].onkeydown = FuncKeyboard;
            }

            </script>

      </head>
      
      <body>

            <form action="Sample.asp" method="post">

                  <input type="text" name="text1" id="text1" value="">

                  <input type="text" name="text2" id="text2" value="">
                  
                  <input type="submit" name="submit1" id="submit1" value="Submit">

            </form>

      </body>

</html>

Can you please provide me equivalent VBScript for this JAVAScript ?

Thanks
0
Comment
Question by:kishore_peddi
  • 3
  • 2
6 Comments
 
LVL 29

Assisted Solution

by:Göran Andersson
Göran Andersson earned 200 total points
ID: 20392414
Why would you want it in VBScript, when Javascript works in any browser, and VBScript only in Internet Explorer?

Anyhow, this should work:

<script language="VBScript">
           
Function FuncKeyboard(e)
      If window.event.keyCode = 13
            document.forms(0).submit()
      End If
End Function

Function Init()
      document.forms(0).elements("text2").onkeydown = FuncKeyboard;
End Function

window.onload = Init

</script>
0
 
LVL 25

Expert Comment

by:imitchie
ID: 20392453
<script language="javascript">
function FuncKeyboard(e)
  key = window.event.keyCode
  if (key = 13) then
    document.forms[0].submit()
  end if
end function
function initme()
  document.forms[0].elements["text2"].onkeydown = FuncKeyboard;
end function

Set Window.Onload=GetRef("initme")
</script>
0
 
LVL 25

Expert Comment

by:imitchie
ID: 20392463
correction to this function

function initme()
  Set document.forms[0].elements["text2"].onkeydown = GetRef("FuncKeyboard")
end function

if it complains about the "Set" statements, remove the Set keyword
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:kishore_peddi
ID: 20392714
Here is the code...still i have some bugs:

<html>

      <head>
            
            <script language="vbscript">
            
            Sub MethodKeyboard(e)

                  If (window.event.keyCode = 13) Then
                        document.forms(0).submit()
                  End If

            End Sub

            Sub Init()

                  document.forms(0).elements("text2").onkeydown = GetRef(MethodKeyboard)
            
            End Sub

            Set window.onload = GetRef(Init)

            </script>

      </head>
      
      <body>

            <form action="Sample.asp" method="post">

                  <input type="text" name="text1" id="text1" value="">

                  <input type="text" name="text2" id="text2" value="">
                  
                  <input type="submit" name="submit1" id="submit1" value="Submit">

            </form>

      </body>

</html>

Can you please check ?

Thanks
0
 
LVL 25

Accepted Solution

by:
imitchie earned 300 total points
ID: 20392734
GetRef requires the parameter to be a String. Make sure you quote them, like

 Set window.onload = GetRef("Init")
0
 

Author Comment

by:kishore_peddi
ID: 20392762
imitchie:

Great...works fine.

Thanks
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

Question has a verified solution.

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

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
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…

809 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