views:

316

answers:

3

Hi, Don't know how to do this at all, but if the onclick of a button is similar to below:

onclick="ConfirmAvailable();"
function ConfirmAvailable()
{
 if (document.getElementById("AvailableCB").checked)
 {
  return YesNoDialog("'Are you sure?'");
 }
 else
 {
  return true;
 }
}

Is it possible, if I set ConfirmAvailable()="" using Excel VBA, to reset it to what is above, or even to set the output to =true all the time? The results are passed to another function, so I need it to return true, but ideally, I'd like to change it to nothing, then return it to its original state, if possible. Any help would be appreciated, as I'm not good with this stuff.

+1  A: 

Assuming the Checkbox's name is AvailableCB, and the name of the button is ConfirmAvailable, the VBA version of what you're looking to do should look something like this.

   Public Function ConfirmAvailable_Click()
       ConfirmAvailable_Click = False ' default value = false '
       If AvailableCB.Value = True Then ConfirmAvailable_Click = True ' if checked, true '
   End Function

If the button name is something else, just call this function from its _Click() method.

A. Scagnelli
Thanks A. Scagnelli.I'll give it a go.Is it possible to get VBA to rewrite the function to be the same as above?
DOS
Doesn't really work, as its writing an Excel VBA function, but won't replace the existing function.Is it possible to do this, or to get the onclick to call a different function? The function would have to be loaded somewhere that the page can take it from.
DOS
The above *is* a VBA function. What are you asking for when you say "Is it possible to get VBA to rewrite the function to be the same as above"?
A. Scagnelli
Hi. Sorry if I'm not being clear.Basically, I'm trying to turn off the function above in a VBA macro, and pass the result of true to the next java function, then replace the function as it was, so that I leave the page as I originally found it.
DOS
Ah. You might want to try setting the function to NULL inside the JavaScript, then.
A. Scagnelli
But unfortunately I don't have access to change the JavaScript. Its a page that I'm opening to change information on for work.Not sure if what I'm asking is even possible.
DOS
It may not be possible. Since your function is called "ConfirmAvailable," it may be there to protect against possible collisions; if this is the case, you don't want to remove the data protection.
A. Scagnelli
Hmmm.. I have in idea what each function does. One of them just displays the dialog box to confirm you want to confirm availability (as above), so I just want to be able to do this without confirmation, and then turn the confirmation back on again.
DOS
To do that, you'll need to be able to change the JavaScript, I'm afraid. There's no way to edit JavaScript with VBA if you don't have the ability to modify the JavaScript in the first place.
A. Scagnelli
"Leaving the page as you originally found it" doesn't really make sense. Even if you alter the function on a copy of the page served to you, it won't alter the page for any other user or even the next time you view that page. You would need access to the server to actaully make a permanent change to the page
barrowc
Thanks.So, if I use something like .document.all.ConfirmAvailable = "" (which means the function no longer exists), I can't change it back using something like .document.all.ConfirmAvailable = "{if (document.getElementById("AvailableCB").checked) {return YesNoDialog("'Are you sure?'"); }else{return true;}}"
DOS
+1  A: 

Simple answer: try turning off JavaScript in the browser. An onclick macro that returns true or false often controls whether a link should be followed or not. If JavaScript is off then the link should be followed regardless. Whether this works will depend on how much of the rest of the site requires JavaScript to be enabled

barrowc
Hi barrowc, unfortunately JavaScript is required for many other items in the page.does anyone know if its possible to inject code into the page?
DOS
+1  A: 

Hi, I've found this seems to work if I save the page to my C drive, but this does not accept the changes on the "live" page, and I don't have permission to make the change on the "live" page.

WebBrowser1.document.btnwhatever.attachEvent "onclick", WebBrowser1.document.parentWindow.next_clicked()

I still don't know how to change the function next_clicked(), or the format to pass it back to the page, but as I don't have access on the "live" page I can't do it anyway.

Thanks all for the help and for looking into this for me.

DOS