Alex
Alex

Reputation: 3405

Why this javascript executes in Chrome but not in Firefox?

I need to set the "cmd" hidden text to the values below. Chrome executes this scripts, but Firefox (at least 3.6) doesn't.

I've checked the java in firefox, also the "execute javascript" option. I've been running jquery stuff in firefox quite well. What should I do?

function envia() {

    frm = document.forms['detalha'];
    tx = frm.elements("cmd");

    tx.value = '0';
    alert('document pressed' + document.pressed);
    if (document.pressed == '2') {
        tx.value = '2';
    } else if (document.pressed == '3') {
        tx.value = '3';
    } else if (document.pressed == '4') {
        tx.value = '4';
    }
    return true;
}
<form name="detalha" action="/publicopj/Altera" onsubmit="envia()">

<input type="submit" value="Save" name="acao" onclick="document.pressed=3"/>

Thanks in advance.

Upvotes: 0

Views: 102

Answers (1)

Marc B
Marc B

Reputation: 360792

document.forms[...].elements is an array, not a function. You've got () on your .elements bit, trying to call it as a function.

tx = frm.elements["cmd"];  // note the square brackets

Upvotes: 2

Related Questions