Creating button dynamically not working in firefox..please help

S

ShutterMan

I have a function that creates input buttons dynamically...

function $NEW_BUTTON(id, content, parentId, cssclass, onclick)
{
var ctrl = document.createElement("input");
ctrl.id = id;
ctrl.setAttribute("name", id);
ctrl.setAttribute("value", content);
ctrl.setAttribute("class", cssclass);
ctrl.setAttribute("type", "button");
ctrl.setAttribute("onclick", "javascript:" + onclick);
$ID(parentId).appendChild(ctrl); // equivalent to
document.getElementById()
}

In both IE7 and FF3, the buttons are created. But in Firefox, the
value of the button is always "undefined". (In IE its correct). Any
ideas?

Thanks
 
G

GTalbot

I have a function that creates input buttons dynamically...

    function $NEW_BUTTON(id, content, parentId, cssclass, onclick)
        {
        var ctrl = document.createElement("input");
        ctrl.id = id;
        ctrl.setAttribute("name", id);
        ctrl.setAttribute("value", content);
        ctrl.setAttribute("class", cssclass);
        ctrl.setAttribute("type", "button");
        ctrl.setAttribute("onclick", "javascript:" + onclick);

There is no need for the "javascript:" to be appended. Anyway, I'm not
sure this way of defining an onclick event handler can work.
        $ID(parentId).appendChild(ctrl);   // equivalent to
document.getElementById()
    }

In both IE7 and FF3, the buttons are created.  But in Firefox, the
value of the button is always "undefined".  (In IE its correct).  Any
ideas?

Thanks

Can you post an URL?

Regards, Gérard
 
S

ShutterMan

The button event handler isnt my issue at the moment..its that the
text on the button is "undefined" in FF3, but whatever its supposed to
be under IE7 (correct behavior).

(Back to the handler question tho...IE7 DOESNT perform the function,
where FF3 does...go figure..)
 
A

Adam C.

The button event handler isnt my issue at the moment..its that the
text on the button is "undefined" in FF3, but whatever its supposed to
be under IE7 (correct behavior).

(Back to the handler question tho...IE7 DOESNT perform the function,
where FF3 does...go figure..)

Not sure what $ID is (I'm assuming it resolves to
document.getElementById), but when I open up a JavaScript shell and
run

var aDiv = document.getElementById("divId"); // for a page with a div
with ID "divId"
var ctrl = document.createElement("input");
ctrl.id="xyz"
ctrl.setAttribute("name", "xyz")
ctrl.setAttribute("value", "someValue")
ctrl.setAttribute("type", "button")
aDiv.appendChild(ctrl)

it works just fine in FF3 for me... a button labelled "someValue"
shows up inside aDiv.
 
S

ShutterMan

I figured it out - and thank you very much for looking at it... the
code is ok.. the calling routine is:

$NEW_BUTTON(id, tablesList[t].text, "div1", "", "somefunction();");

Firefox doesnt like ".text"...it apparently prefers ".textContent".
All is well after that. I don't understand why the FF developers wont
make concessions for these kinds of things, for compatibility sake.
Standards are great and all, but at the cost of driving people mad?
They could have easily implemented a ".text". :/ I could say the same
for Microsoft, but we all know they wont adhere to standards. Oh
well.. again, thanks for looking at it, much appreciated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,731
Latest member
MarcyGipso

Latest Threads

Top