How to call on-click Javascript function in VBA

mackypogi

New Member
Joined
Jul 21, 2013
Messages
23
Hi Experts!

In a manual process, when I click the save button, it will pop-up a confirm() javascript function, so I need to click the "OK" to proceed. I am automating an upload function in a web page.
I have a problem executing an on-click function in a web page using VBA.
see below the javascript code of the "save" button.
HTML:
<input type="submit" name="cmdsave" 
value="Save" o n c l i c k="return submitbutton_click();" 
id="cmdsave" class="button" style="width:50px;" /> 
I have no problem in clicking the "save" button, I can do that using code below
Code:
Set ElementNameV = HTMLDoc.getElementsByName("cmdsave")
ElementNameV(0).click
The problem is when I click the "save" button, the confirm pop-up will appear and the macro will stop running from there unless the pop-up had been pressed.
and so I came up in another solution removing the pop-up message using the code below.
HTML:
ElementNameV(0).removeAttribute ("o n c l i c k")
ElementNameV(0).setAttribute "o n c l i c k", "return true"
ElementNameV(0).click
Using that code, I am able to attach the attachment without any problem, the pop-up is gone and I am able to click save.
But the problem is, I am able to attach the file but it is not uploading in the site. Then when I review the HTML code of the web page.
using the ******* function it calls the submitbutton_click(); Javascript function, and the code for that is below
HTML:
function submitbutton_click() {
        document.getElementById('FileAttachement2_hdnButtonFlag').value = "SAVE";
	    var submitbutton = document.getElementById('cmdDownSave');
		var uploadobj=document.getElementById('FileAttachement2_Uploader1');
		if(!window.filesuploaded)
		{
		   if (!ConfirmSave()) return false;
			if(uploadobj.getqueuecount()>0)
			{
                
				uploadobj.startupload();
			}
			else
			{
				//var uploadedcount=parseInt(submitbutton.getAttribute("itemcount"))||0;
				//if(uploadedcount>0)
				//{
					return true;
				//}
				//alert("Please browse files for upload");
			}
			return false;
		}
		window.filesuploaded=false;
		return true;
	}
HTML:
function ConfirmSave()
{
var Ok = confirm('Are you sure all Documents and Information are attached and correct before saving?');

if(Ok)
return true;
else
return false;
}
Reviewing the javascript codes, I think the upload will only run when I execute the javascript function "uploadobj.startupload();" but then I had no success in running the javascript function.

here are the codes I have tried so far:
HTML:
Call HTMLDoc.parentWindow.execScript("submitbutton_click();")    '//this one doesn't worked
Call HTMLDoc.parentWindow.execScript("uploadobj.startupload();")    '//doesn't worked also

RePost in : How to call ******* Javascript function in VBA

http://www.vbaexpress.com/forum/sho...avascript-function-in-VBA&p=324274#post324274
 
Last edited:

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,214,599
Messages
6,120,448
Members
448,966
Latest member
DannyC96

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top