473,473 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Creating button dynamically not working in firefox..please help

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
4 1786
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: David | last post by:
I have a one-line script to add an onunload event handler to the body of the document. The script is as follows: document.getElementsByTagName("BODY").onunload=function s() {alert("s")} Now...
5
by: sam | last post by:
Hi all, I am dynamically creating a table rows and inerting radio buttons which are also dynamically created. Everything works fine in Firefox as expected. But I am not able to select radio...
7
by: nathaniel.k.lee | last post by:
Is it not possible, in IE, to dynamically click a radio button? I'm grabbing some values from a database and using them to populate radio buttons on a page. I have alternate code for Firefox...
3
by: lcjohnso | last post by:
Hi all, Does anyone know if there is an easy way to create the html representation of an HTMLElement object in javascript? I'm attempting to update the innerHTML property of a div element to...
3
by: patrickkellogg | last post by:
I have this code when you click the buttom is suppose to add a job history. it works with firefox, opera, but not ie. (please note - new entries don't have all the elements in them yet, but...
5
by: SalamElias | last post by:
I am creating several chkBoxes dynamically and assigning an event handler in the Page_load as foillows ***************************** Dim chkCatOption As CheckBox = New CheckBox chkCatOption.Text...
8
by: Harvey Schmidlapp | last post by:
I have a fairly complex form (generated by means of an ASP 3 page). The form is used to define a query against a database. After running a query, the user hits their browser's back button and goes...
2
by: Peter | last post by:
I have a HoverMenuExtender which contains an asp:PlaceHolder, this place holder gets a dynamically created User Control and this control contrains a Button. The problem I am having is the Button...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.