In the following code I create an array with an object that has 3 properties.
I then dynamically create a table wherein one of the cells I create a button.
The button has several parameters, which it is suppose to send with the onclick event handler. One of the parameters is the array (see line 34 of code).
However when I click on the rendered button, I get this error message that says: "missing ] after element list". -
function mapNlistJobs(cPoint, cJob, cPrjctName, cPrjctAddr, cDept, cTitle, cLat, cLon)
-
{
-
var cArray = new Array();
-
cArray[cArray.length] = {job:cTitle, pName:cPrjctName, pAddr:cPrjctAddr};
-
-
var cText = "Job # "+cJob+"<br />"+cPrjctName+"<br />"+cPrjctAddr;
-
var tr, td;
-
-
tbody = document.getElementById("closeJobs");
-
-
//add job row
-
tr = tbody.insertRow(tbody.rows.length);
-
-
//make new cell
-
td = tr.insertCell(tr.cells.length);
-
-
//fill in content
-
td.innerHTML = cJob;
-
-
//make new cell
-
td = tr.insertCell(tr.cells.length);
-
-
//fill in content
-
td.innerHTML = cPrjctName;
-
-
//make new cell
-
td = tr.insertCell(tr.cells.length);
-
-
//could not use this option because I am already using ' and " as delimiters
-
// td.innerHTML = '<input type="button" value="Center" class="InputText" onClick="centerOnThis( '+cLat+', '+cLon+', '+cTitle+', '+cPrjctName+', '+cPrjctAddr+' );"/>'
-
-
-
//here is where I am trying to include the array as a parameter.
-
td.innerHTML = '<input type="button" value="Center" class="InputText" onClick="centerOnThis( '+cLat+', '+cLon+', '+cArray+' );"/>'
-
-
}
-
@Claus Mygind
I decided to solve my problem by using a global array and just track the array element in the button -
var exchangeArray = new Array();
-
-
function mapNlistJobs(cPoint, cJob, cPrjctName, cPrjctAddr, cDept, cTitle, cLat, cLon)
-
{
-
exchangeArray[exchangeArray.length] = {job:cTitle, pName:cPrjctName, pAddr:cPrjctAddr};
-
var aCnt = exchangeArray.length-1
-
.
-
.
-
.
-
class="InputText" onClick="centerOnThis( '+cLat+', '+cLon+', '+aCnt+' );"/>'
-
}
-
-
function centerOnThis(cLat, cLon, cCnt)
-
{
-
-
var cPoint = new google.maps.LatLng(cLat,cLon);
-
map.setCenter(cPoint, 17);
-
-
var j = exchangeArray[cCnt].job
-
var p = exchangeArray[cCnt].pName
-
var a = exchangeArray[cCnt].pAddr
-
map.openInfoWindowHtml(map.getCenter(), "Job # <a href='/SXYZ/job.exe?SEARCH="+j+' target="_blank'+'">'+j+"</a><br />"+p+"<br />"+a);
-
}
-
-
6 2156 @Claus Mygind
I decided to solve my problem by using a global array and just track the array element in the button -
var exchangeArray = new Array();
-
-
function mapNlistJobs(cPoint, cJob, cPrjctName, cPrjctAddr, cDept, cTitle, cLat, cLon)
-
{
-
exchangeArray[exchangeArray.length] = {job:cTitle, pName:cPrjctName, pAddr:cPrjctAddr};
-
var aCnt = exchangeArray.length-1
-
.
-
.
-
.
-
class="InputText" onClick="centerOnThis( '+cLat+', '+cLon+', '+aCnt+' );"/>'
-
}
-
-
function centerOnThis(cLat, cLon, cCnt)
-
{
-
-
var cPoint = new google.maps.LatLng(cLat,cLon);
-
map.setCenter(cPoint, 17);
-
-
var j = exchangeArray[cCnt].job
-
var p = exchangeArray[cCnt].pName
-
var a = exchangeArray[cCnt].pAddr
-
map.openInfoWindowHtml(map.getCenter(), "Job # <a href='/SXYZ/job.exe?SEARCH="+j+' target="_blank'+'">'+j+"</a><br />"+p+"<br />"+a);
-
}
-
-
a) in IE .innerHTML is read-only for tables
b) event listeners are way more comfortable than event attributes.
@Dormilich
Thank you for your answer.
a) My user base is strictly FireFox
b) I have only started to dabble in event listeners and do not have a thorough understanding of them as yet. But I do agree if I could move to that level of proto-typing my code it would be more global.
Event Listeners as such have barely anything to do with prototyping. however, some pros and cons of Event Listeners:
pros - they allow you to add/remove functions to an Event anytime, anywhere
- they allow you to execute functions in the capturing or bubbling phase of the Event Flow
- your HTML becomes cleaner (separation of structure and behaviour)
cons - IE does not implement the DOM-level-2 EventTarget Interface (= addEventListener), therefore you require a workaround (readily available, just google or ask me).
- IE’s implementation sucks, don’t use it. (you really do yourself a favour)
- most JavaScript frameworks don’t support event capturing
@Dormilich
Thanks for your clarification. I was really on board with you until the very last comment in "cons"
most JavaScript frameworks don’t support event capturing
Not sure how that would impact the javaScript I am writing?
Not sure how that would impact the javaScript I am writing?
as always, it depends on the actual script. there are cases, where event capturing is the better (and sometimes only) choice.
as for an example (an image slider game), there is a table created, where every cell has a click handler. if the game is won, all click actions have to be suppressed. either you stop the click event before it reaches the table cells (which can only be done in the capturing phase, since <td> is already the target) or you remove all handlers or remove/replace the table.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Thomas Philips |
last post by:
To experiment with filtering, I define a function f(x,k) as follows
>>> def f(x,k=2):
return x%k==0
I can check that it works by typing
>>> f(10,3)
False
Now, I try to filter a range using...
|
by: Nautilus |
last post by:
Taken from a couple very similar samples on the net, I'm having
trouble passing a parameter to a PHP file.
Here's all the JS code ... it creates an image object and modifies
it's src to make a...
|
by: Mike Carroll |
last post by:
I have a COM server that's generally working ok. But one of its methods,
when the IDL gets read by the Intertop layer, has parameters of type "out
object".
The C# compiler tells me that it...
|
by: martin_saucier |
last post by:
I have a problem where when passing object ByRef in a WebService, some object
members are being return as Nothing when coming back from the call ? How do I
fix this ?
Thanks.
Martin
|
by: dawg1998 |
last post by:
I am able to populate a DropDownList control within multiple rows of a
GridView with the following code:
``````````````````````````````````````````````````````
<asp:GridView id="gvGridView"...
|
by: TS |
last post by:
I was under the assumption that if you pass an object as a param to a method
and inside that method this object is changed, the object will stay changed
when returned from the method because the...
|
by: =?Utf-8?B?UmF2aQ==?= |
last post by:
Hi,
I'm trying to pass values of different data-types to a web-service. I
thought it would be easier to box these values and pass them as a
System.object parameter, like
public void...
|
by: JackC |
last post by:
Hi,
I create my threads like this:
for(int j = 0; j < 5; j++)
{
boost::thread *thr = new boost::thread(worker_func);
threads.add_thread(thr);
}
|
by: fxeko |
last post by:
Hi all...
I have got a problem about passing data parameter in data report VB6
my problem:
x= "admin"
how to send value of x variabel to data report
Thanks for your advabced
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |