Buddies,
I have a web page to create HTML buttons dynamically as in the “formDivColorPi cker” function - //////////////////////////////////////////////////////////////////////////////////// version 1 : using global variables //////////////////////////////////////////////////////////////////
- var _textField, _divColorPicker; // global vars
-
-
window.onload = function()
-
{
-
_textField = document.getElementById('htxaMessage'); // fill global var *****
-
_divColorPicker= document.getElementById('divColorPicker'); // fill global var ******
-
-
formDivColorPicker(); // no need arguments ******************************
-
}
-
-
function changeFontColor(button)
-
{
-
var fontColor = button.id.split('_');
-
// insertAtCaret function is defined in some where else on the page
-
insertAtCaret(_textField, '[font color=' + fontColor[1] + ']', '[/font]');
-
alert(_divColorPicker.id);
-
}
-
function formDivColorPicker()
-
{
-
var op = _divColorPicker;
-
var c=0;
-
-
for(var i=0, l=JSONColors.length; i<l; i++)
-
{
-
// DOM-dynamically-created HTML buttons
-
-
op.innerHTML += '<input id=' + 'btnColor_' + JSONColors[i].name + ' type=button onclick="changeFontColor(this);" style="width:16px; height:16px; background-color:' + JSONColors[i].value + '" />  ';
-
-
c++;
-
if(c==COLOR_BUTTONS_PER_ROW)
-
{
-
op.innerHTML +="<br><span style='margin-left:150px'>";
-
c=0;
-
op.innerHTML +="</span>";
-
}
-
}
-
}
-
-
… markups on the page
-
<tr>
-
<td>
-
<div id="divColorPicker" style="display:none; margin-left:150px; position: static">
-
</div>
-
</td>
-
</tr>
-
-
<tr style="height:40%">
-
<td align="left" valign="top">
-
<textarea id=htxaMessage cols="70" rows=3 onkeyup="htxaMessage_checkIfEnterKeyHit(event);"></textarea>
-
…
-
-
The codes work fine with the “changeFontColor” function if I use global variables such as var _textField, _divColorPicker; on window load event and I need to pass this to that function when I create buttons using DOM in the “formDivColorPicker” function.
-
However, if I do not use global variables and the form of functions as follows, then I get javascript runtime error like “object is undefined…” in function “changeFontColor” for arguments like textField and divColorPicker:
-
-
-
/////////////////////////// version 2 not using global vars but argument passing ////////
-
//var _textField, _divColorPicker; // commented out
-
-
window.onload = function()
-
{
-
var _textField = document.getElementById('htxaMessage'); // local var
-
var _divColorPicker= document.getElementById('divColorPicker');// local var
-
-
formDivColorPicker(_textField, _divColorPicker); // call the function with arguments ******************************
-
}
-
-
function changeFontColor(textField, divColorPicker){
-
var fontColor = button.id.split('_');
-
// insertAtCaret function is defined in some where else on the page
-
insertAtCaret(_textField, '[font color=' + fontColor[1] + ']', '[/font]'); // error******
-
alert(divColorPicker.id); // error ******
-
}
-
-
function formDivColorPicker(textField, divColorPicker){
-
var op = _divColorPicker;
-
var c=0;
-
-
for(var i=0, l=JSONColors.length; i<l; i++)
-
{
-
// DOM-dynamically-created HTML buttons
-
-
op.innerHTML += '<input id=' + 'btnColor_' + JSONColors[i].name + ' type=button onclick="changeFontColor(‘ + textField + ‘,’ + divColorPicker + ‘);" style="width:16px; height:16px; background-color:' + JSONColors[i].value + '" />  ';
-
-
c++;
-
if(c==COLOR_BUTTONS_PER_ROW)
-
{
-
op.innerHTML +="<br><span style='margin-left:150px'>";
-
c=0;
-
op.innerHTML +="</span>";
-
}
-
}
-
}
Thanks in advance for any help or idea.
johnjsforum
1 2263 acoder 16,027
Recognized Expert Moderator MVP
The underscores need to be removed on lines 71 and 76. You've forgotten to remove them to use the passed arguments.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: John VanRyn |
last post by:
Ok, I have XML like this (XML Exhibit A) that I read in from a file
ala .. $doc->load("./Template.xml"); because I could not figure out
how to set the !DOCTYPE element.
------ XML Exhibit A-----
<?xml version="1.0" standalone="no" ?>
<!DOCTYPE graph SYSTEM "graph.dtd">
<graph/>
--------------
|
by: Carlo Sette |
last post by:
Hi all,
when I try to Parse a sample XML ducument Python display the follow error
message:
---------------------------------------------------------------------------
Traceback (most recent call last):
File "./mysql.py", line 57, in ?
DOM=xml.dom.minidom.parseString(XML)
File "/usr/local/lib/python2.3/xml/dom/minidom.py", line 1925, in...
|
by: Skip Montanaro |
last post by:
I'm getting somewhat painfully acquainted with xml.dom.minidom. What is the
relationship between its documentElement attribute and its childNodes list?
I thought XML documents consisted of a single, possibly compound, node. Why
is a list of childNodes needed?
Thx,
Skip
|
by: Steve Roberts |
last post by:
I want to write a graphical view of an XML tree, using a DOM interface, that
allows the XML tree to be edited, with nodes being added or removed.
For this I was going to create a basic tree structure, mirroring the
structure held in the DOM. Every node of the new tree would reference a
matching DOM node. However, I'm not familiar enough with...
|
by: Chris |
last post by:
Hi,
the docs say :
"The Xml-document is not loaded into memory when using XmlTextReader, as
opposed to using the DOM where the entire document is loaded in memory"
but, when using XmlTextReader, how can I parse then if the document is not
loaded ?
something must be loaded no ?
| |
by: segfalt |
last post by:
Hey All, I'm wondering if someone can give me a hand with the
following.
I'm frequently updating xml files, sometimes in bulk updates. I'm
having trouble getting the output formatted nicely (not one long line).
Here is an example.
I would create the doc using something like the following code:
$dom = new...
|
by: YAD |
last post by:
How do you decide which DOM level you should use? I've been told level 2
is the "modern" approach, but also saw a website that said use level 0
any time you can.
Should you use higher-level code where lower-level code works? Does
lower-level code fail in modern browsers? What are the issues you have
to worry about?
--
Yet another Dan
|
by: Greg Copeland |
last post by:
I am attempting to freeze an application which uses the dom.minidom
parser. When I execute my application, I get an import error of:
ImportError: No module named dom.minidom. During the freeze process,
I can see:
freezing xml ...
freezing xml.dom ...
freezing xml.dom.NodeFilter ...
freezing xml.dom.domreg ...
freezing...
|
by: Lie |
last post by:
Why this generates AttributeError, then not?
Python 2.5.2 (r252:60911, Apr 21 2008, 11:17:30)
on linux2
Type "help", "copyright", "credits" or "license" for more information.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'dom'
<module 'xml.dom' from...
|
by: Simon Willison |
last post by:
I'm having a horrible time trying to get xml.dom.pulldom to consume a
UTF8 encoded XML file. Here's what I've tried so far:
<msg>Simon\xe2\x80\x99s XML nightmare</msg>
"""
('START_DOCUMENT', <xml.dom.minidom.Document instance at 0x6f06c0>)
('START_ELEMENT', <DOM Element: msg at 0x6f0710>)
....
UnicodeEncodeError: 'ascii' codec can't...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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 we have to send another system
|
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |