Search code examples
javascriptfirefoxversioncompatibility

JavaScript document.forms[0].field.value compatibility


I have a form with a radioButton in IBM domino. The radioButton is to control the operation that user want to do. With JS I check that one option is selected before form will be send. I test it with Firefox Developer Edition (52oa) and works, but in client doesn't work, it works with Firefox 31. My doubt is since which version Firefox is compatible that method to get the value?

The code is this:

var control = document.forms[0].OperacionDNI.value;
if (control == 1 || control == 2) {
    guardar();
}
else{
    alert("Por favor, debe elegir una operación a realizar");
}

In my pc if one option is selected, call guardar() function, but in client PC shows the alert.

I think must be the method, any other idea will be welcome.


Solution

  • Apparently, it does not work on earlier versions of Firefox.

    A simple workaround would be to select the element directly by it's id attribute.

    var control = document.getElementById('OperacionDNI').value;
    if (control == 1 || control == 2) {
        guardar();
    }
    else{
        alert("Por favor, debe elegir una operación a realizar");
    }