IHTMLInputElement::put_value doesn't set editbox value?
IHTMLInputElement::put_value doesn't set editbox value?
I want to set a the editbox in a html-form.
IHTMLInputElement::put_value returns S_OK, but the text of the
editbox is not set, instead it's just cleared. Can you please help me
take a look?
The following is my C++ code:
CString filename = _T("C:\\temp\\test.htm");
_variant_t varFlags(0L);
_variant_t varMissing(0L);
m_browser.Navigate(filename, &varFlags, &varMissing, &varMissing,
&varMissing);
LPUNKNOWN lpUnk = m_browser.GetControlUnknown();
IWebBrowser2Ptr ipWebCtrl(lpUnk);
VARIANT_BOOL bBusy = VARIANT_TRUE;
while (bBusy == VARIANT_TRUE)
ipWebCtrl->get_Busy(&bBusy);
IDispatchPtr ipDispatch;
HRESULT hr = ipWebCtrl->get_Document(&ipDispatch);
IHTMLDocument2Ptr ipHtmlDoc2(ipDispatch);
if (!ipHtmlDoc2)
return;
IHTMLElementCollectionPtr ipElements;
ipHtmlDoc2->get_all(&ipElements);
if (!ipElements)
return;
long count = 0;
ipElements->get_length(&count);
for(long i = 0; i < count; i++)
{
LPDISPATCH lpItem;
ipElements->item(CComVariant(i), CComVariant(i), &lpItem);
IHTMLInputElementPtr ipInput(lpItem);
if(!ipInput)
continue;
// Edit-Field?
BSTR bstrType;
ipInput->get_type(&bstrType);
if (CString(bstrType) == "text")
{ // Fill in Text
CString sTemp (_T("TestVal"));
BSTR bstrNewValue = sTemp.AllocSysString ();
ipInput->put_value (bstrNewValue);
SysFreeString(bstrNewValue);
}
}
The following is my test.htm:
<html>
<head>
</head>
<body>
<script language="JScript"><!--
function GoNext()
{
id = document.all.userID.value;
window.external.GoNext("$#pageName:#UserIDPage.htm$#userID:#" + id +
"$#");
}
//--></script>
<table border="0" width="60%" align="center">
<tr>
<td width="100%">
<form>
<p><input type="text" name="myEditBox" size="20"> Edit</p>
</form>
<form>
<p><input type="checkbox" name="myCheck1" value="ON">
Chk1
<input type="checkbox" name="myCheck2" value="ON"
checked>Chk2
<input type="checkbox" name="myCheck3" value="ON">Chk3</p>
</form>
<form">
<p><input type="radio" value="V1" checked name="myRadio"> Op1
<input type="radio" name="myRadio" value="V2">
Op2 <input type="radio" name="myRadio" value="V3">Op3</
p>
</form>
<form>
<p><select size="1" name="myDropDown">
<option selected>Sel 1</option>
<option>Sel 2</option>
<option>Sel 3</option>
</select> Sel</p>
</form>
<form>
<p align="center"><input type="text" name="userID" size="20"></p>
</form>
<form>
<p align="center"><input type="button" onclick="GoNext();"
value="Next >>" name="NextBtn"></p>
</form>
</td>
</tr>
</table>
</body>
</html>