Solved

Can you please provide me equivalent VBScript for this JavaScript ?

Posted on 2007-12-02
6
881 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now