HighDots Forums  

How do I pass a string to a function?

Javascript JavaScript language (comp.lang.javascript)


Discuss How do I pass a string to a function? in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
jmDesktop
 
Posts: n/a

Default How do I pass a string to a function? - 07-01-2008 , 11:04 AM






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='javascriptlace("
+ p[1] + "," + p[0] +

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

I have changed it to this:

document.getElementById("message").innerHTML
+=
"<br>" + (i + 1) + ": <a
href='javascriptlace("
+ 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="javascriptlace(42.415392,-71.110948,"
ctl00_contentplaceholder1_formview1_mytextbox="" ,="" 127="" main=""
st,="" medford,="" ma="" 02155,="" usa="" )="">

and this translates to:

javascriptlace(42.415392,-71.110948, Why is it dropping after the
comma?

It should be:


javascriptlace(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.


Reply With Quote
  #2  
Old   
GArlington
 
Posts: n/a

Default Re: How do I pass a string to a function? - 07-01-2008 , 11:16 AM






On Jul 1, 4:04 pm, jmDesktop <needin4mat... (AT) gmail (DOT) com> wrote:
Quote:
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='javascriptlace("
+ p[1] + "," + p[0] +

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

I have changed it to this:

document.getElementById("message").innerHTML
+=
"<br>" + (i + 1) + ": <a
href='javascriptlace("
+ 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="javascriptlace(42.415392,-71.110948,"
ctl00_contentplaceholder1_formview1_mytextbox="" ,="" 127="" main=""
st,="" medford,="" ma="" 02155,="" usa="" )=""

and this translates to:

javascriptlace(42.415392,-71.110948, Why is it dropping after the
comma?

It should be:

javascriptlace(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='javascriptlace("
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...


Reply With Quote
  #3  
Old   
jmDesktop
 
Posts: n/a

Default Re: How do I pass a string to a function? - 07-01-2008 , 11:19 AM



On Jul 1, 11:16*am, GArlington <garling... (AT) tiscali (DOT) co.uk> wrote:
Quote:
On Jul 1, 4:04 pm, jmDesktop <needin4mat... (AT) gmail (DOT) com> wrote:





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='javascriptlace("
* * * * * * * * * * * * * + p[1] + "," + p[0] +

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

I have changed it to this:

* * * * * * * * * * * * * document.getElementById("message").innerHTML
+=
* * * * * * * * * * * * * "<br>" + (i + 1) + ": <a
href='javascriptlace("
* * * * * * * * * * * * * + 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="javascriptlace(42.415392,-71.110948,"
ctl00_contentplaceholder1_formview1_mytextbox="" ,="" 127="" main=""
st,="" medford,="" ma="" 02155,="" usa="" )=""

and this translates to:

* javascriptlace(42.415392,-71.110948, *Why is it dropping after the
comma?

It should be:

javascriptlace(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='javascriptlace("
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.


Reply With Quote
  #4  
Old   
Thomas 'PointedEars' Lahn
 
Posts: n/a

Default Re: How do I pass a string to a function? - 07-01-2008 , 12:07 PM



jmDesktop wrote:
Quote:
On Jul 1, 11:16 am, GArlington <garling... (AT) tiscali (DOT) co.uk> wrote:
On Jul 1, 4:04 pm, jmDesktop <needin4mat... (AT) gmail (DOT) com> wrote:
and this translates to:
javascriptlace(42.415392,-71.110948, Why is it dropping after the
comma?
It should be:
javascriptlace(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='javascriptlace("
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


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.