By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,600 Members | 1,861 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,600 IT Pros & Developers. It's quick & easy.

Creating button dynamically not working in firefox..please help

P: n/a
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
Jul 20 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Jul 20, 12:23*am, ShutterMan <scott.hut...@gmail.comwrote:
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
Jul 20 '08 #2

P: n/a
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..)
On Jul 20, 1:10*am, GTalbot <newsgr...@gtalbot.orgwrote:
On Jul 20, 12:23*am, ShutterMan <scott.hut...@gmail.comwrote:
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
Jul 20 '08 #3

P: n/a
On Jul 20, 1:18*am, ShutterMan <scott.hut...@gmail.comwrote:
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..)

On Jul 20, 1:10*am, GTalbot <newsgr...@gtalbot.orgwrote:
On Jul 20, 12:23*am, ShutterMan <scott.hut...@gmail.comwrote:
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

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.
Jul 20 '08 #4

P: n/a
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.
On Jul 20, 2:00*am, "Adam C." <adam...@gmail.comwrote:
On Jul 20, 1:18*am, ShutterMan <scott.hut...@gmail.comwrote:
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..)
On Jul 20, 1:10*am, GTalbot <newsgr...@gtalbot.orgwrote:
On Jul 20, 12:23*am, ShutterMan <scott.hut...@gmail.comwrote:
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

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.
Jul 20 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.