views:

540

answers:

1

Hey,

I'm writing a VB application that interacts with the HTML DOM.

If I go to this page:

https://edit.yahoo.com/registration

And then try to change the "I prefer content from" SELECT box in the top right to "Yahoo! Asia" from the default option selected, I can do so using this command:

Document.Forms.regFormBody.preferredcontent.selectedIndex = 10

It successfully changes it. But the problem is that it's not the same behavior as if you manually changed that option to Yahoo! Asia using your mouse.

If you try to do so manually without using the DOM, after changing it, the page refreshes.

I'm assuming it's a javascript call or something that refreshes that page according to which option is selected, but I've tried to replicate that behavior using DOM and I just can't figure it out.

Can someone help? Thanks in advance.

A: 

Your looking for the onChange event. Of course there is a possibility that the form is getting submitted by some other event, perhaps onBlur.

Updated following additional questions from comments

Apparently bound by the following line:

YAHOO.util.Event.on("preferredcontent", "change", ymem_reg.switchPrefContent);

Which calls the following:

ymem_reg.switchPrefContent = function(e) {
    var Dom = YAHOO.util.Dom || false;
    if (Dom) {
        var oForm = Dom.get("regFormBody");
        var sToIntl = this.options[this.selectedIndex].value;
        var yregFormValidator = (typeof yregFormValidator !== "undefined") ? yregFormValidator: false;
        var fieldsWithDefaults = Dom.get(["firstname", "secondname", "dd", "yyyy"]);
        var clearVal = function(el) {
            if (el !== null && ymem_reg.fieldHasDefaultVal(el)) {
                el.value = "";
            }
        }
        if (oForm !== null && sToIntl !== "") {
            if (yregFormValidator) {
                yregFormValidator.disable();
            }
            var oInput = document.createElement("input");
            oInput.setAttribute("type", "hidden");
            oInput.setAttribute("name", "IntlSwapBtn");
            oInput.setAttribute("id", "IntlSwapBtn");
            oForm.appendChild(oInput);
            Dom.batch(fieldsWithDefaults, clearVal);
            oForm.submit();
        }
    }
}
Jonathan Sampson
But if you examine the SELECT box in question, you'll notice that there's no onChange behavior apparently binded to it. Can you find the javascript call it makes when it gets changed?
Answer Updated.
Jonathan Sampson
That's awesome. Not sure how you managed to dissect that, but I'll take it. But I still can't figure out how to use the DOM to replicate that behavior. I try to do this in VB:' Document.Forms.regFormBody.preferredcontent.selectedIndex = 10' Set newElem = IE.Document.createElement("button")' newElem.setAttribute "onclick", "ymem_reg.switchPrefContent();"' IE.Document.Body.InsertBefore newElem, IE.Document.Body.FirstChild' IE.Document.Body.FirstChild.Clickbut that doesn't work :( The new button is created but when I click on it, nothing happens. Any more tips?