By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,299 Members | 1,054 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,299 IT Pros & Developers. It's quick & easy.

How do I pass a string to a function?

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.