• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Setting values in forms via javascript and onchange issue

I have read enough to know that this is how things are. When you call the following code in javascript, the combobox will change value as expected. However the onchange event does not get fired. From reading this is totally normally (however stupid).

var elem = document.getElementById("someComboBoxForm")

elem.value=7;



So, I have things that need to know that the value changed. How can I work around this? From what i have read, IE and Firefox/Others need to be treated slightly differently.

My head is ready to explode. 2 hours into this issue and I have gotten almost no where.
 
The onchange event fires when the user makes the change, not when code does it. So just call the onchange function yourself:

<select name='title' onchange='javascript:Titleonchange();'>
<option value='Mr'>Mr</option>
<option value='Mrs'>Mrs</option>
<option value='Other'>Other</option>
</select>

Code:
var elem = document.getElementById("title")
elem.value='Mr';
Titleonchange();


or turn it into a function

Code:
function SetCombo(value){
    var elem = document.getElementById("title")
    elem.value=value;
    Titleonchange();

}
 
I just tried what you said and I don't know why but it does not work.

At first I did not do it right as I did not see what you are doing. Now that I see it, I still can't get the damned thing working.

And I have tried this path before. I can't call the damned method as it "does not exist". I'm doing something simple wrong and those are the things that are hard to debug.

EDIT: Side effects from javascript that is more complex than a simple example is what is driving me nuts.
 
Last edited:
I HATE JAVASCRIPT.

OK, i read a bit on the issue I was having in regards to Xyz is not a function type errors. And I have no idea what is going on. oh. IT WORKS! Luckily I am billing all this nightmare.

What is the difference between these:
Code:
function A () {
    function B(argghhh) {
        // Do Stuff
    }
}

And:

Code:
function A () [
    this.B = function(argghhh) {
        // Do Stuff
    };
}


When I try to call like this:
Code:
var X = new A();
X.B();
 
Last edited:
Assuming the [ after function 1 is a typo, B should cause every instance of A to have a property B which is the function shown.

You can't declare a global function inside a function definition like you try to in 1. You can assign a closure to a property, but you can't just declare another function inside a definition like that. It gets treated as an object instead of a global definition, and since you don't assign it to anything, it goes to Tumbolia.



EDIT:
Lets see if I can make this more clear. In both cases, A is being declared as a global function. In both cases, B is actually being treated as creating a new function object - only the top level gets created as a global function, within those declarations any further declarations are closures.

Code 2 therefore creates an object, and then assigns to it A.B. A creates an object and then creates a closure, but the closure is not assigned to anything so it just vanishes.

You don't get any syntax errors because creating a closure and then doing nothing with it is in fact valid syntax. No matter what the class of object is. In fact, while in most languages this would be a big NO, this is valid javascript:

Code:
false;

Nothing missing there, no typos. Just false by itself is perfectly valid. As is, say, 1; or "Bob"; It's no doubt due to the way JS handles functions - they're all objects, and some don't return values, so if the language has to allow things like that. If it didn't, when you tried to call any function it would always have to return a value, and you'd always have to do something with it. Which means you can't use functions and equivalent to subroutines, and then the programmers storm the castle.


So, In A, the function did exist - but it didn't get assigned to anything, and went out of scope instantly.
 
Last edited:
Back
Top