473,385 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Passing an object as a parameter

Claus Mygind
571 512MB
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".

Expand|Select|Wrap|Line Numbers
  1. function mapNlistJobs(cPoint, cJob, cPrjctName, cPrjctAddr, cDept, cTitle, cLat, cLon)
  2. {
  3.     var cArray = new Array();
  4.     cArray[cArray.length] = {job:cTitle, pName:cPrjctName, pAddr:cPrjctAddr};
  5.  
  6.     var cText  = "Job # "+cJob+"<br />"+cPrjctName+"<br />"+cPrjctAddr;
  7.     var tr, td;
  8.  
  9.        tbody = document.getElementById("closeJobs");
  10.  
  11.     //add job row
  12.     tr = tbody.insertRow(tbody.rows.length);
  13.  
  14.     //make new cell
  15.     td = tr.insertCell(tr.cells.length);
  16.  
  17.     //fill in content
  18.     td.innerHTML =    cJob;
  19.  
  20.     //make new cell
  21.     td = tr.insertCell(tr.cells.length);
  22.  
  23.     //fill in content
  24.     td.innerHTML =    cPrjctName;
  25.  
  26.     //make new cell
  27.     td = tr.insertCell(tr.cells.length);
  28.  
  29. //could not use this option because I am already using ' and " as delimiters
  30. //    td.innerHTML =    '<input type="button" value="Center" class="InputText" onClick="centerOnThis( '+cLat+', '+cLon+', '+cTitle+', '+cPrjctName+', '+cPrjctAddr+' );"/>'
  31.  
  32.  
  33. //here is where I am trying to include the array as a parameter.
  34.     td.innerHTML =    '<input type="button" value="Center" class="InputText" onClick="centerOnThis( '+cLat+', '+cLon+', '+cArray+' );"/>'
  35.  
  36. }
  37.  
May 21 '10 #1

✓ answered by Claus Mygind

@Claus Mygind
I decided to solve my problem by using a global array and just track the array element in the button
Expand|Select|Wrap|Line Numbers
  1. var exchangeArray = new Array();
  2.  
  3. function mapNlistJobs(cPoint, cJob, cPrjctName, cPrjctAddr, cDept, cTitle, cLat, cLon)
  4. {
  5.     exchangeArray[exchangeArray.length] = {job:cTitle, pName:cPrjctName, pAddr:cPrjctAddr};
  6.     var aCnt =    exchangeArray.length-1
  7. .
  8. .
  9. .
  10. class="InputText" onClick="centerOnThis( '+cLat+', '+cLon+', '+aCnt+' );"/>'
  11. }
  12.  
  13. function centerOnThis(cLat, cLon, cCnt)
  14. {
  15.  
  16.     var cPoint = new google.maps.LatLng(cLat,cLon);
  17.     map.setCenter(cPoint, 17);
  18.  
  19.     var j = exchangeArray[cCnt].job
  20.     var p = exchangeArray[cCnt].pName
  21.     var a = exchangeArray[cCnt].pAddr
  22.     map.openInfoWindowHtml(map.getCenter(), "Job # <a href='/SXYZ/job.exe?SEARCH="+j+' target="_blank'+'">'+j+"</a><br />"+p+"<br />"+a);
  23. }
  24.  
  25.  

6 2156
Claus Mygind
571 512MB
@Claus Mygind
I decided to solve my problem by using a global array and just track the array element in the button
Expand|Select|Wrap|Line Numbers
  1. var exchangeArray = new Array();
  2.  
  3. function mapNlistJobs(cPoint, cJob, cPrjctName, cPrjctAddr, cDept, cTitle, cLat, cLon)
  4. {
  5.     exchangeArray[exchangeArray.length] = {job:cTitle, pName:cPrjctName, pAddr:cPrjctAddr};
  6.     var aCnt =    exchangeArray.length-1
  7. .
  8. .
  9. .
  10. class="InputText" onClick="centerOnThis( '+cLat+', '+cLon+', '+aCnt+' );"/>'
  11. }
  12.  
  13. function centerOnThis(cLat, cLon, cCnt)
  14. {
  15.  
  16.     var cPoint = new google.maps.LatLng(cLat,cLon);
  17.     map.setCenter(cPoint, 17);
  18.  
  19.     var j = exchangeArray[cCnt].job
  20.     var p = exchangeArray[cCnt].pName
  21.     var a = exchangeArray[cCnt].pAddr
  22.     map.openInfoWindowHtml(map.getCenter(), "Job # <a href='/SXYZ/job.exe?SEARCH="+j+' target="_blank'+'">'+j+"</a><br />"+p+"<br />"+a);
  23. }
  24.  
  25.  
May 21 '10 #2
Dormilich
8,658 Expert Mod 8TB
a) in IE .innerHTML is read-only for tables
b) event listeners are way more comfortable than event attributes.
May 21 '10 #3
Claus Mygind
571 512MB
@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.
May 27 '10 #4
Dormilich
8,658 Expert Mod 8TB
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
May 27 '10 #5
Claus Mygind
571 512MB
@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?
Jun 4 '10 #6
Dormilich
8,658 Expert Mod 8TB
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.
Jun 4 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
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...
2
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...
5
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...
0
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
0
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"...
7
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...
8
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...
2
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); }
3
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
0
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...
0
isladogs
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...
0
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
0
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...
0
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...
0
BarryA
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...
0
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...

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.