473,788 Members | 3,030 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

passing variable problem or quotation syntax conundrum

35 New Member
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 1663
iam_clint
1,208 Recognized Expert Top Contributor
Expand|Select|Wrap|Line Numbers
  1. theMenu +="<a href=javascript:open(f, '"+element+"')>"+element+"</a><br>";
  2.  
Nov 22 '06 #2
carllucas
35 New Member
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
carllucas
35 New Member
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
6558
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 courses to pass the correct option value and then be displayed at the following URL: http://www.dslextreme.com/users/kevinlyons/selectResults.html I am passing countries, products, and courses. The first two display
4
49575
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
36414
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 variable with the "ref" syntax then it gets passed as a reference to the object and any changes to
20
1998
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> bool1=True lst1= def func1(arg1): arg1.append(4)
11
4471
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 accomplish. // - - - - - - - - begin code - - - - - - - typedef int sm_t; typedef int bg_t; sm_t sm; bg_t bg;
17
3604
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 (*fcmp)() = &cmp_fcn; qsort(..., fcmp); then everything works. But if instead I code qsort as:
3
2041
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 this string. I did a re something like
12
2595
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 by value temporaries are created?(I'm not touching yet the cases where standard allows optimizations from the side of implementations to avoid copying) If so, please quote part of the standard that says that. Assuming it is true, I can imagine two...
4
9183
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 = myBar() ) when passing by reference? Every method I've tried gives me syntax
0
9655
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, 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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10363
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10110
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9964
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 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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7517
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5398
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4069
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
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.