passing parameter to a function in javascript

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
littlecoder
Forum Commoner
Posts: 26
Joined: Fri Oct 17, 2008 4:36 am

passing parameter to a function in javascript

Post by littlecoder »

hi,
how can i pass ""(Quotes) as a parameter to a function in JavaScript from HTML?
function showfn(s,a)
{
alert(s+a);
}
<body onload = "showfn("",'str')"
>
The "" in showfn("",'str') is not a blank value or a null , but a Quote like the quote in ("How are you").
Any help would be greatly appreciated.
User avatar
kaszu
Forum Regular
Posts: 749
Joined: Wed Jul 19, 2006 7:29 am

Re: passing parameter to a function in javascript

Post by kaszu »

Escape quote with slash

Code: Select all

function showfn(s,a)
{
alert(s+a);
}
<body onload = "showfn(\"\",'str')"
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: passing parameter to a function in javascript

Post by VladSun »

kaszu wrote:Escape quote with slash

Code: Select all

function showfn(s,a)
{
alert(s+a);
}
<body onload = "showfn(\"\",'str')"
Or use single quotes:

Code: Select all

function showfn(s,a)
{
alert(s+a);
}
<body onload = "showfn('','str')"
There are 10 types of people in this world, those who understand binary and those who don't
littlecoder
Forum Commoner
Posts: 26
Joined: Fri Oct 17, 2008 4:36 am

Re: passing parameter to a function in javascript

Post by littlecoder »

hi,
thank you for your suggestions...
i tried out your method but i am not getting anything...

it seems the javascript function is not being called...
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: passing parameter to a function in javascript

Post by VladSun »

Did you put it in a SCRIPT tag?

Code: Select all

 <head> <script>function showfn(s,a){alert(s+a);}</script> </head><body onload="showfn('','str')">...
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply