The following excel vba macro will open a webpage and insert "500010" into a text box. If you manually type the same number into the textbox, a dropdown box will appear with further selections. This doesn't occur with the programmatic number entry. I've tried a number of ways to programmatically get this dropdown box to appear, a few are shown in my code, but to no avail.
Sub test()
URL = "http://www.bseindia.com/markets/equity/EQReports/StockPrcHistori.aspx?expandable=7&flag=0"
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.navigate URL
Do Until (ie.readyState = 4 And Not ie.Busy)
DoEvents
Loop
ie.Document.getElementById("ctl00_ContentPlaceHolder1_GetQuote1_txtscrip_code").Value = 500010
' click the textbox to get the dropdown box to appear
ie.Document.getElementById("ctl00_ContentPlaceHolder1_GetQuote1_txtscrip_code").fireevent ("onClick")
ie.Document.getElementById("ctl00_ContentPlaceHolder1_GetQuote1_txtscrip_code").Click
end sub
If I look at the source code for the webpage, I see the following prior to information about the textbox.
<script type="text/javascript">
function cleartext1(a) {
if (a.value == "Scrip code/Scrip Name")
a.value = '';
}
function Filltext1() {
a.value == "Scrip code/Scrip Name"
}
function ClearTextBox(a)
{
if (a.value == a.defaultValue) a.value = "";
}
function FillTextBox(a)
{
if (a.value == "") a.value = a.defaultValue;
}
function HiddenValue(hdn) {
var hvalue = document.getElementById(hdn).value;
if (hvalue != "")
{
var s1=hvalue.split("|");
location.href = "/StockReach/AdvanceStockReach.aspx?scripcode=" + s1[0];
return true;
}
else
return false;
}
// function chk(e)
// {
// if(window.event)
// {
// var key=window.event.keyCode;
// if (key == 13)
// {
// var btn = document.getElementById('btnGetQuote');
// // HiddenValue('hdnIdAsset');
//
// btn.click();
// //btn.focus();
// }
// }
// }
</script>
<div id="ctl00_ContentPlaceHolder1_GetQuote1_Pn1" onkeypress="return noenter(event);">
<table border="0" cellspacing="0" cellpadding="2" align="left">
<tr>
<td style ="padding-right:10px;">
<input value="" id="divshow" type="hidden" />
<input value="" id="hdnIdAsset" type="hidden" /><input name="ctl00$ContentPlaceHolder1$GetQuote1$hdnValue" type="hidden" id="ctl00_ContentPlaceHolder1_GetQuote1_hdnValue" />
<input name="ctl00$ContentPlaceHolder1$GetQuote1$txtscrip_code" type="text" maxlength="500" id="ctl00_ContentPlaceHolder1_GetQuote1_txtscrip_code" value="Scrip code/Scrip Name" class="textbox2" onclick="javascript:selecttxt(this);" onkeypress="javascript:noenter(event);return chkkey(event,this);" onfocus="cleartext1(this);" onblur="FillTextBox(this)" onkeyup="javascript:showDivSelect(event,'Asset','http://www.bseindia.com/common/backpageAsset.aspx',this,this.value,3,'0',false);" style="width:160px;" />
I'm not very familiar with writing javascript functions for vba, but I tried putting the following in my macro, but it created an error.
f = "function (hiddenvalue) 'http://www.bseindia.com/markets/equity/EQReports/StockPrcHistori.aspx?/StockReach/AdvanceStockReach.aspx?scripcode=500010').value = 'True';}" ie.Document.parentWindow.execScript f, "jscript" ie.Document.getElementById("ctl00_ContentPlaceHolder1_GetQuote1_txtscrip_code").Click
Am I on the right track, is a javascript function in my code what's needed here? Can someone help me come up with the code to get the dropdown box to appear?..TIA, Ron