views:

49

answers:

4

I'm working on a script and it works fine in IE and Chrome, but the links do not work in Firefox.

Basically I am using php to query a database and generate some links inside the page.

Example of the relevant link code:

<TD class="bodycopyblue"
    onmouseover="this.style.background='#FFFF80';this.style.cursor='pointer'"
    onmouseout="this.style.background='#FFFFFF'"
    onclick="getAccountDetails(<?php print $accountinfo['audio_account_id']; ?>)"
>view CDRs</TD>

The onmouseover/out code works fine. The onclick doesn't seem to be.

The function the link calls:

function getAccountDetails(account_id) {

 accountform.aid.value=account_id;
 accountform.submit();
}

Which is submitting a form:

<FORM id="accountform"
    action="accountdetails.php?month=<?php print $cdate['mon']; ?>&year=<?php print $cdate['year']; ?>"
    method="post">
<INPUT id="aid" name="aid" type="hidden" value=0>
</FORM>

The Form doesn't seem to be showing up correctly... but it's a simple form with a single hidden field. Posted using a link generated by some php. I installed firebug, but either from my ignorance of its operation or nothing being wrong, it reports no errors.

A: 

What is the resulting HTML that's generated? Do a "view source" in Firefox and paste your code into the question. You will most likely see malformed HTML.

Alex
A: 

try

function getAccountDetails(account_id) {

        document.getElementById('aid').value=account_id;
        accountform.submit();
}
Scott Evernden
This does work, although I have to do a document.getElementById for the account for and call submit from that result.
Valrus
A: 

Firebug 1.4 and FF 3.5 work a little tricky, you need to open Firebug's console (F12, or click the Firebug icon in the lower right) and then reload the page with the console open. Click on the "Console" tab once your Firebug window is open, maybe it will show you an error.

My only other suggestion is to add a semilcolon after your JS statement.

onclick="getAccountDetails(<?php print $accountinfo['audio_account_id']; ?>);"

Firefox is usually very forgiving though--it's odd that it works in the other browsers and not FF. As a final test, take out the mouseover and mouseout events and just leave the onclick and see if it works by itself.

jnunn
Thanks for the info on firebug, it did show a java script error. "accountform is undefined". Apprently it didn't like how I was referencing the element in my function.
Valrus
A: 
function getAccountDetails(account_id) {
    accountform.aid.value=account_id;
    accountform.submit();
}

What's accountform? If you've not done a var accountform= ... anywhere you won't get any variable with that name, except for in IE which erroneously creates variables for named items in window scope.

Don't rely on this, set accountform explicitly:

function getAccountDetails(account_id) {
    var accountform= document.getElementById('accountform');
    accountform.elements.aid.value=account_id;
    accountform.submit();
}
bobince
accountform is the id of the form I'm trying to submit.
Valrus
Then you'll have to use `document.getElementById` to put it in a variable.
bobince