Results 1 to 6 of 6

Thread: Disable/enable javascript function of a web page

  1. #1
    Join Date
    Mar 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Disable/enable javascript function of a web page

    Hi All,

    I am not much sure that I am in the real forum to post my this question. But I found this forum most suitable for my question.

    My question is how to disable and enable the execution of a JavaScript function in a web page using DOM in VB6.

    I have a project in VB6, checking some conditions in a third party webpage.

    This web page has a JavaScript Function namely

    HTML Code:
    <script language="javascript">
    
    function next_clicked()
    {
    .......
    .......
    .......
    }
    </Script>
    
    <input type="button" name="Submit" value="NEXT" onClick=next_clicked() >
    In my project I check some conditions in some text fields of the web page. If these conditions are false I want to disable the execution of the function next_clicked() when the user clicks on the NEXT button.
    And if the conditions are true I want to enable the execution of the same function upon the NEXT button click.

    To disable the execution I wrote the following VB code and it work fine.

    WebBrowser1.document.getElementsByName("Submit")(0).onclick = ""

    But once it is disabled I cannot to enable again when the conditions are true.

    If anybody has idea to enable the execution of this disabled function please help me.

    With regards,
    Nasreen

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Ok, what this:

    Code:
    WebBrowser1.document.getElementsByName("Submit")(0).onclick = ""
    does is obliterate the onclick function. Now, I am not super familiar with VB but, if it can set an onclick, it should be able to set a variable, something like (to disable):

    Code:
    WebBrowser1.document.getElementsByName("Submit")(0).c_var = 1
    and, to enable:

    Code:
    WebBrowser1.document.getElementsByName("Submit")(0).c_var = 0
    Then in your javascript function:

    Code:
    function next_clicked()
    {
    if (document.getElementsByName("Submit")[0].c_var)
    return;
    .......
    .......
    The onclick event will fire (when c_var=1) but, the function will exit without taking any action. When c_var hasn't been declared or is 0, the function will operate as usual.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Mar 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi jscheuer1

    Thanks for your replay,

    But the problem here is the web site is not mine and I have no control on it at all to change the scripts. It is a thrid party web site we use to work on it in our company as we are one of their correspondent and they may not change their script only for our purpose, because they have a wide range network and correspondents.

    I only take the control of that web site in my VB project using HTML DOM. So your this idea is not applicable in my case.

    If you have any new option pls help me.

    With regards,
    Nasreen

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Well, that being the case you need to reinstate the onclick function, perhaps something like this to restore the function:

    Code:
    WebBrowser1.document.getElementsByName("Submit")(0).onclick = WebBrowser1.next_clicked
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Mar 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi Mr. jscheuer1

    Thanks for you help and best cooperation.
    Now it is working.
    Thanks once again.

    With regards,
    Nasreen

  6. #6
    Join Date
    Mar 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Access javascript variable in VB6

    Hi Mr. jscheuer1

    Can we access (read/write) the javascript variables, in functions or out of functions, in VB6 using DOM ?

    Any idea ?

    With regards,
    Nasreen

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
  •