Board index » cppbuilder » changing onsubmit event does not work

changing onsubmit event does not work


2003-12-19 07:55:12 PM
cppbuilder24
Hi
By traversing the list of elements in an IHTMLDocument2 object I found the
form element (there is only one in my HTML page) and changed its onsubmit
event to my own function
i.e:
IHTMLFormElement* mForm;
:
<find form element and assign it to mForm
:
TVariant vNewScript;
V_VT(&vNewScript) = VT_BSTR;
V_BSTR(&vNewScript) = WideString("function anonymous() {alert('1');return
true;}").Copy();
hr=mForm->put_onsubmit(vNewScript); //remove the inline onsubmit script
if (FAILED(hr))
{
ShowMessage("Failed to enter new script");
}
mForm->submit();
However when I submit the old function in the onsubmit event is executed and
not my new function which should display an alert box with a value of 1
Do I somehow need to reload the document in memory???
Thanks
Tim
 
 

Re:changing onsubmit event does not work

"Tim Chemaly" < XXXX@XXXXX.COM >wrote in message
Quote
V_VT(&vNewScript) = VT_BSTR;
If you read the documentation for the onsubmit event, the VARIANT must
contain an IDispatch, not a BSTR:
IHTMLFormElement::onsubmit Property
msdn.microsoft.com/workshop/browser/mshtml/reference/ifaces/formelement/onsubmit.asp
Gambit
 

Re:changing onsubmit event does not work

OK got that :-)
I created a sink which works fine when I click on the submit button on the
web page.
My overrided sink event only displays a message box with the text "new
event"
which is fine.
I used the IHTMLFormElement::put_onsubmit(nSink); function to replace the
default event with my own
However when I submit from my C++ code using IHTMLFormElement::submit()
the old event specified in the HTML file is called??? How is that possible??
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"Tim Chemaly" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>V_VT(&vNewScript) = VT_BSTR;

If you read the documentation for the onsubmit event, the VARIANT must
contain an IDispatch, not a BSTR:

IHTMLFormElement::onsubmit Property


msdn.microsoft.com/workshop/browser/mshtml/reference/ifaces/formeleme
nt/onsubmit.asp
Quote


Gambit


 

{smallsort}

Re:changing onsubmit event does not work

"Tim Chemaly" < XXXX@XXXXX.COM >wrote in message
Quote
However when I submit from my C++ code using
IHTMLFormElement::submit() the old event specified
in the HTML file is called??? How is that possible??
Again, please read the documentation:
IHTMLFormElement::submit Method
msdn.microsoft.com/workshop/browser/mshtml/reference/ifaces/formelement/submit.asp
Remarks
The IHTMLFormElement::submit method does not invoke the onsubmit event
handler. Call the onsubmit event handler directly.
Gambit