VB + DHTML Applications Question
Results 1 to 2 of 2

Thread: VB + DHTML Applications Question

  1. #1
    Registered User
    Join Date
    Jul 2001
    Location
    California
    Posts
    18

    Question VB + DHTML Applications Question

    I have noticed that all the events in DHTML Applications are called someobject_onclick() as boolen. First question why is it onclick and why is everything sent as a boolen does that have to deal with it being on a HTML page? Thanks,

    Ryan
    Systems Student
    Meriam Library, CSU Chico
    sstudent at csuchico.edu

  2. #2
    Registered User
    Join Date
    Jan 1999
    Location
    London, Great Britain
    Posts
    300

    Lightbulb

    The _OnClick is the event name for when that particular object is clicked. The use of underscore (_) then the event name after the object name is VB convention. This is different to the . notation for methods/parameters as it helps distinguish the from object events.

    There are two ways of defining events on objects in DHTML.
    One is to use the explicit function-style, which is how JavaScript is mostly used:

    [code]
    ...
    <input type="button" onCl!ck="myFunction();" value="Click Me!" name="myButton">
    ...
    <script language="vbscript">
    function myFunction()
    msgbox "Hello!"
    end function
    </script>
    ...
    </pre><hr></blockquote>

    The other is the event style of VB:

    [code]
    ...
    &lt;input type="button" value="Click Me!" name="myButton"&gt;
    ...
    &lt;script language="vbscript"&gt;
    sub myButton_OnCl!ck()
    msgbox "Hello!"
    end sub
    &lt;/script&gt;
    ...
    </pre><hr></blockquote>
    (note the spelling of OnCl!ck as the UBB doesn't like this!!)

    These two scripts do exactly the same thing, but notice the subtle difference in the way we define the OnClick event.

    There other events too (OnMouseOver, OnMouseOut, for example) but the most often used one is obviously the OnClick event.

    As for Boolean values, is not because it sends everything as a Boolean value (the event passes no parameters, it only fires when the click happens) but because you should return a Boolean value (true/false) as good programming convention.

    You do not need to return any values at all, but if someone is relying on a return value from the OnClick event, then obviously you need to return something.

    An example would be where you want to check if an object has been clicked on before submitting a form, or before clicking another object.

    For full details on the OnClick event, and others, take a look at the <a href="http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/events/onclick.asp" target="_blank">Microsoft MSDN DHTML Reference</a>.

    HTH,
    I'd rather die peacefully in my sleep like my Grandfather,
    than screaming in terror like his passengers.
    Jim Harkins
    <a href="http://www.Horrible.Demon.co.uk/" target="_blank">http://www.Horrible.Demon.co.uk/</a>

Bookmarks

Posting Permissions

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