Results 1 to 6 of 6
  1. #1
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Onsubmit for VB?

    As most of this forum's readers may already know, you can prevent an HTML Form from submitting itself in the usual automatic ways (e.g., when the user hits the Enter key) by putting the following event handler in the form's opening tag (or whatever it's called; a web coder I am not):

    <pre>onsubmit="return false;"</pre>

    I have today discovered (a slow, painful discovery from which I'm still recovering) that this only works (in IE6 anyway) if the web page includes a reference to Javascript. There doesn't need to actually be any substantive Javascript (all the actual script can be VBScript). You can instead just include an empty Javascript tag in the header (i.e., <script language="javascript"></script> will do).

    So that works, but it's kludgy. My question is: Is there a VBScript equivalent to onsubmit="return false" that prevents the automatic submission of a form?

  2. #2
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Onsubmit for VB?

    I think I'm now in a position to answer my own question. If you add a function to the page called frmMyForm_OnSubmit, it automatically gets called when the submission event fires (as the result of an automatic submission). If you have the function return false (in all cases, if that's what you want, or after some data-validation fails), the submission is aborted. In other words, this separate function seems to be the VB equivalent of Javascript's onsubmit="return false;":
    <pre>Function frmMyForm_OnSubmit()
    frmMyForm_OnSubmit = False
    End Function</pre>


  3. #3
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Onsubmit for VB?

    Hi Steve

    Have a look at the thread on this site....there are some great snippets:

    Disable form submit on enter
    Jerry

  4. #4
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Onsubmit for VB?

    Thanks for the link, although I would note (for the benefit of future readers of this thread) that it only deals with Javascript -- and particularly Javascript workarounds for the fact that onsubmit = "return false;" apparently doesn't work in at least some versions of Firefox.

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Onsubmit for VB?

    I've never noticed that the default scripting language for IE is VBScript. I'm surprised if that's the case. But your JavaScript workaround probably is better for cross-browser compatibility than trying to find a VBScript equivalent for IE.

  6. #6
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Onsubmit for VB?

    Thanks for the advice.

    I don't know if IE6 (my version) has a "default scripting language." I just found out (the hard way) that it doesn't give effect to onsubmit="return false;" unless there's an explicit Javascript reference on the page.

    I'm using VBScript because the HTML forms involved are on pages that are just for my own personal use, and I'm still (unwisely, perhaps) using IE, and I'm already familiar with VBScript (but not Javascript).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •