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

How do I pass a string to a function?

I have searched much but cannot find answer to this seemingly simple
question. I have a function that builds an html element like this,
which works fine:

document.getElementById("message").innerHTML
+=
"<br>" + (i + 1) + ": <a
href='javascript:place("
+ p[1] + "," + p[0] +

")'>" + result.Placemark[i].address + "</
a>";

I have changed it to this:

document.getElementById("message").innerHTML
+=
"<br>" + (i + 1) + ": <a
href='javascript:place("
+ p[1] + "," + p[0] + ",'" + o.id + "','" +
result.Placemark[i].address +

"')'>" + result.Placemark[i].address + "</
a>";

There is a single quote on either side of o.id and result..., if you
cannot tell ", ' ". But this single quote never gets built. I have
tried \, escape(), String.charFromCode(39) with eval, and other
things. It just breaks the href up and what gets generated is:

<a href="javascript:place(42.415392,-71.110948,"
ctl00_contentplaceholder1_formview1_mytextbox="" ,="" 127="" main=""
st,="" medford,="" ma="" 02155,="" usa="" )="">

and this translates to:

javascript:place(42.415392,-71.110948, Why is it dropping after the
comma?

It should be:
javascript:place(42.415392,-71.110948,'ctl00_contentplaceholder1_formview1_myt extbox','127
main st, medford, ma')

It is turnning the o.id and result.Placemark[i].address in to
variables, and I cannot figure out why. I want to pass them as
strings to another function.

I am using Firefox 3. Thank you for any help.

Jul 1 '08 #1
3 1782
On Jul 1, 4:04 pm, jmDesktop <needin4mat...@gmail.comwrote:
I have searched much but cannot find answer to this seemingly simple
question. I have a function that builds an html element like this,
which works fine:

document.getElementById("message").innerHTML
+=
"<br>" + (i + 1) + ": <a
href='javascript:place("
+ p[1] + "," + p[0] +

")'>" + result.Placemark[i].address + "</
a>";

I have changed it to this:

document.getElementById("message").innerHTML
+=
"<br>" + (i + 1) + ": <a
href='javascript:place("
+ p[1] + "," + p[0] + ",'" + o.id + "','" +
result.Placemark[i].address +

"')'>" + result.Placemark[i].address + "</
a>";

There is a single quote on either side of o.id and result..., if you
cannot tell ", ' ". But this single quote never gets built. I have
tried \, escape(), String.charFromCode(39) with eval, and other
things. It just breaks the href up and what gets generated is:

<a href="javascript:place(42.415392,-71.110948,"
ctl00_contentplaceholder1_formview1_mytextbox="" ,="" 127="" main=""
st,="" medford,="" ma="" 02155,="" usa="" )="">

and this translates to:

javascript:place(42.415392,-71.110948, Why is it dropping after the
comma?

It should be:

javascript:place(42.415392,-71.110948,'ctl00_contentplaceholder1_formview1_myt extbox','127
main st, medford, ma')

It is turnning the o.id and result.Placemark[i].address in to
variables, and I cannot figure out why. I want to pass them as
strings to another function.

I am using Firefox 3. Thank you for any help.
Most likely problem is to do with your "<a href='javascript:place("
Note the opening single quote in href, so when the browser encounters
next single quote it considers it to be end of href string.
You will have to escape those, or (I think this is more likely to
work) use double quotes to encapsulate your strings...
Jul 1 '08 #2
On Jul 1, 11:16*am, GArlington <garling...@tiscali.co.ukwrote:
On Jul 1, 4:04 pm, jmDesktop <needin4mat...@gmail.comwrote:


I have searched much but cannot find answer to this seemingly simple
question. *I have a function that builds an html element like this,
which works fine:
* * * * * * * * * * * * * document.getElementById("message").innerHTML
+=
* * * * * * * * * * * * * "<br>" + (i + 1) + ": <a
href='javascript:place("
* * * * * * * * * * * * * + p[1] + "," + p[0] +
* * * * * * * * * * * * * ")'>" + result.Placemark[i].address + "</
a>";
I have changed it to this:
* * * * * * * * * * * * * document.getElementById("message").innerHTML
+=
* * * * * * * * * * * * * "<br>" + (i + 1) + ": <a
href='javascript:place("
* * * * * * * * * * * * * + p[1] + "," + p[0] + ",'" + o.id + "','" +
* * * * * * * * * * * * * result.Placemark[i].address +
* * * * * * * * * * * * * "')'>" + result.Placemark[i].address + "</
a>";
There is a single quote on either side of o.id and result..., if you
cannot tell ", ' ". *But this single quote never gets built. *I have
tried \, escape(), String.charFromCode(39) with eval, and other
things. *It just breaks the href up and what gets generated is:
<a href="javascript:place(42.415392,-71.110948,"
ctl00_contentplaceholder1_formview1_mytextbox="" ,="" 127="" main=""
st,="" medford,="" ma="" 02155,="" usa="" )="">
and this translates to:
* javascript:place(42.415392,-71.110948, *Why is it dropping after the
comma?
It should be:
javascript:place(42.415392,-71.110948,'ctl00_contentplaceholder1_formview1_*my textbox','127
main st, medford, ma')
It is turnning the o.id and result.Placemark[i].address in to
variables, and I cannot figure out why. *I want to pass them as
strings to another function.
I am using Firefox 3. *Thank you for any help.

Most likely problem is to do with your "<a href='javascript:place("
Note the opening single quote in href, so when the browser encounters
next single quote it considers it to be end of href string.
You will have to escape those, or (I think this is more likely to
work) use double quotes to encapsulate your strings...- Hide quoted text -

- Show quoted text -
I knew as soon as I posted I'd figure it out. I just use double
quotes. "\"". I didn't know you could use double quotes. I thought
that javascript would only take single quotes. I tried it and it
worked.
Jul 1 '08 #3
jmDesktop wrote:
On Jul 1, 11:16 am, GArlington <garling...@tiscali.co.ukwrote:
>On Jul 1, 4:04 pm, jmDesktop <needin4mat...@gmail.comwrote:
>>and this translates to:
javascript:place(42.415392,-71.110948, Why is it dropping after the
comma?
It should be:
javascript:place(42.415392,-71.110948,'ctl00_contentplaceholder1_formview1_Â*m ytextbox','127
main st, medford, ma')
It is turnning the o.id and result.Placemark[i].address in to
variables, and I cannot figure out why. I want to pass them as
strings to another function.
I am using Firefox 3. Thank you for any help.
Most likely problem is to do with your "<a href='javascript:place("
Note the opening single quote in href, so when the browser encounters
next single quote it considers it to be end of href string.
You will have to escape those, or (I think this is more likely to
work) use double quotes to encapsulate your strings...

I knew as soon as I posted I'd figure it out. I just use double
quotes. "\"". I didn't know you could use double quotes. I thought
that javascript would only take single quotes. I tried it and it
worked.
More clearly thinking people would have simply RTFM before they started
coding in a programming language they don't know. But then again those
people would also have read the FAQ of a newsgroup before posting in it and
then would not have needed to ask this question in the first place as the
approach is wrong in the first place, and they would have properly quoted.

<http://jibbering.com/faq/>
PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Jul 1 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Woodster | last post by:
I have declared the following std::map<std::string, std::string> myMap; to pass myMap to functions should I be declaring functions as: void function(std::map<std::string, std::string>); ...
110
by: Mr A | last post by:
Hi! I've been thinking about passing parameteras using references instead of pointers in order to emphasize that the parameter must be an object. Exemple: void func(Objec& object); //object...
1
by: Mark Dicken | last post by:
Hi All I have found the following Microsoft Technet 'Q' Article :- Q210368 -ACC2000: How to Pass an Array as an Argument to a Procedure (I've also copied and pasted the whole contents into...
0
by: Zlatko Matiæ | last post by:
Hi everybody! Recently I was struggling with client/server issues in MS Access/PostgreSQL combination. Although Access is intuitive and easy to use desktop database solution, many problems...
9
by: Alvin Bruney | last post by:
The more knowledgable I get about this .net world, the more questions I have. ..NET uses pass by reference for all objects....uhhh I mean pass by value. (Couldn't resist this jab) Consider a...
4
by: KC Eric | last post by:
Hi all, I have a dll file, it has a class, say: class Temp, this class has a function which has a delegate as a parameter, say: public void Test(GameOverHandler _overHandler)
2
by: Steve Bottoms | last post by:
Is there any way to pass a login name/password when calling System.Web.Mail.SMTPMail? Can't find anything in the docs or KB... If not, any suggestions to get this functionality short of building...
23
by: Sanjay Kumar | last post by:
Folks, I am getting back into C++ after a long time and I have this simple question: How do pyou ass a STL container like say a vector or a map (to and from a function) ? function: ...
5
by: David++ | last post by:
Hi folks, I would be interested to hear peoples views on whether or not 'pass by reference' is allowed when using a Web Service method. The thing that troubles me about pass-by-reference into...
2
by: =?Utf-8?B?dmlzaHJ1dGg=?= | last post by:
Hi, I have 2 applications running, one Windows application project and the other windows services project. I want to call my Windows application in my windows services. I want to run them as...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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.