Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 934
  • Last Modified:

Can you please provide me equivalent VBScript for this JavaScript ?

<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
kishore_peddi
Asked:
kishore_peddi
  • 3
  • 2
2 Solutions
 
Göran AnderssonCommented:
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
 
imitchieCommented:
<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
 
imitchieCommented:
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
kishore_peddiAuthor Commented:
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
 
imitchieCommented:
GetRef requires the parameter to be a String. Make sure you quote them, like

 Set window.onload = GetRef("Init")
0
 
kishore_peddiAuthor Commented:
imitchie:

Great...works fine.

Thanks
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now