PDA

View Full Version : Disable/enable javascript function of a web page



nasreen
03-10-2007, 06:57 PM
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



<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

jscheuer1
03-10-2007, 07:39 PM
Ok, what this:


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):


WebBrowser1.document.getElementsByName("Submit")(0).c_var = 1

and, to enable:


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

Then in your javascript function:


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.

nasreen
03-11-2007, 05:29 AM
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

jscheuer1
03-11-2007, 06:12 AM
Well, that being the case you need to reinstate the onclick function, perhaps something like this to restore the function:


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

nasreen
03-11-2007, 07:43 AM
Hi Mr. jscheuer1

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

With regards,
Nasreen

nasreen
03-20-2007, 05:20 AM
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