473,395 Members | 1,581 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,395 software developers and data experts.

passing variable problem or quotation syntax conundrum

I'm having issues trying to pass a variable

basically I get information from an external xml document like this

Expand|Select|Wrap|Line Numbers
  1. function run(file) {
  2.     t = file.getElementsByTagName("category");
  3.  
  4.     for(i=0; i<t.length; i++) {
  5.       element = file.getElementsByTagName("category")[i].childNodes[0].nodeValue;
  6.       theMenu +=    "<a href='javascript:open(f, "+
  7.             element+")'>"+
  8.             element+
  9.             "</a><br>";
  10.     }
  11.  
  12.  
  13. }
  14.  
What this does is create a list of the elements tagged "category" with a respective link to a javascript function. this part works because when i hover over the list i get something like "javascript: open(Something)" in the status bar.

to test this i create this function:
Expand|Select|Wrap|Line Numbers
  1. function open(msg) {
  2.    alert(msg);
  3. }
  4.  
However when i click on the links i get an error:

Expand|Select|Wrap|Line Numbers
  1. Error: 'Something' is undefined
  2.  
I think what it is trying to do is find out what is assaigned to 'Something' (or how 'Something is defined)but 'Something' is the definition. 'Something is the definition of element at that part of the for loop.

I figured that a way to solve this is to tell the machine that whatever is assigned to element should be considered a string. But I don't know how to deal with the syntax of 3 quotes in each other because I would essentially need something like this:

Expand|Select|Wrap|Line Numbers
  1.       theMenu +=    "<a href="javascript:open(f, ""+
  2.             element+"")">"+
  3.             element+
  4.             "</a><br>";
  5.  
Notice the 3 "s which ones will be "s and which ones will be 's and what about the 3rd one? Is it a " or a '. I've tried all sorts of combos but I can't figure out the right syntax.

Is there another way around this error? Sorry for the length of this... any help appriciated.
Nov 22 '06 #1
3 1647
iam_clint
1,208 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. theMenu +="<a href=javascript:open(f, '"+element+"')>"+element+"</a><br>";
  2.  
Nov 22 '06 #2
Expand|Select|Wrap|Line Numbers
  1. theMenu +="<a href=javascript:open(f, '"+element+"')>"+element+"</a><br>";
  2.  
I've tried this and it doesn't work.

when I hover over the link the status bar shows "javascript: open(f, "

and when you click the link you get:

"Error: syntax error"

How for example do internet email apps allow the user to click a message title and follow the link. Is there a way I can use this methodoly with XML instead of PHP?
Nov 22 '06 #3
This is my XML document named myLibrary.xml

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <library>
  3.  
  4. <book>
  5.   <title>My Family</title>
  6.   <category>Biography</category>
  7.   <author>John Smith
  8.   <year>2004</year>
  9.   <price>30.00</price>
  10. </book>
  11.  
  12. <book>
  13.   <title>Spooks</title>
  14.   <category>Thriller</category>
  15.   <author>Eric McGee
  16.   <year>2000</year>
  17.   <price>10.99</price>
  18. </book>
  19.  
  20. <book>
  21.   <title>New York</title>
  22.   <category>Travel</category>
  23.   <author>Ellis June
  24.   <year>1998</year>
  25.   <price>13.99</price>
  26. </book>
  27.  
  28. <book>
  29.   <title>Lonely Planet Tokyo</title>
  30.   <category>Travel</category>
  31.   <author>Andrew Bender</author>
  32.   <year>2006</year>
  33.   <price>19.99</price>
  34. </book>
  35.  
  36. <book>
  37.   <title>Angela's Ashes: A Memoir</title>
  38.   <category>Biography</category>
  39.   <author> Frank McCourt</authro>
  40.   <year>1999</year>
  41.   <price>14.95</price>
  42. </book>
  43.  
  44. </library>
  45.  
I could like to create a list of all the categories and when you click on the categories it takes you to the books in those categories.

I'm sure someone's had to do this before can someone please help me.
Nov 23 '06 #4

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

Similar topics

12
by: Kevin Lyons | last post by:
Hello, I am trying to get my select options (courses) passed correctly from the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html I am having difficulty getting the...
4
by: Thomas Miskiewicz | last post by:
Hi! Is using of a double quotation mark with a URL a problem? For example: http://myserver.com/query?field1=something&field2=test&params="field1=test1"+"field2=test2" Regards Thomas
5
by: Andy | last post by:
Hi Could someone clarify for me the method parameter passing concept? As I understand it, if you pass a variable without the "ref" syntax then it gets passed as a copy. If you pass a...
20
by: Gregory Piñero | last post by:
Hey guys, would someone mind giving me a quick rundown of how references work in Python when passing arguments into functions? The code below should highlight my specific confusion: <code> ...
11
by: truckaxle | last post by:
I am trying to pass a slice from a larger 2-dimensional array to a function that will work on a smaller region of the array space. The code below is a distillation of what I am trying to...
17
by: Charles Sullivan | last post by:
The library function 'qsort' is declared thus: void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *)); If in my code I write: int cmp_fcn(...); int...
3
by: eight02645999 | last post by:
hi if i have a string like this "ABCE-123456 ABC_DEF_Suggest(abc def ghi).txt" that needs to be passed to a python script and i wanted to get the words inside the brackets after i passed...
12
by: dave_dp | last post by:
Hi, I have just started learning C++ language.. I've read much even tried to understand the way standard says but still can't get the grasp of that concept. When parameters are passed/returned...
4
by: Chris | last post by:
Suppose I have the following function signature void foo( Bar &myBar); and I want myBar to be an optional parameter, is there a way to do the logical equivalent of void foo( Bar &myBar =...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...

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.