/    Sign up×
Community /Pin to ProfileBookmark

‘ in param for function

hi, i got a problem but dunno how to solve…

<script language=”Javascript” type=”text/javascript”>
function test(temp1) {
alert(temp1);
}
</script>

<input type=checkbox name=one value=1.00 onClick=test(Borussia M’gladbach)>

i think the problem is with the ‘ in M’gladbach. i tried to urlencode it, which gives Borussia+M%27gladbach, but still also cannot.

anyone help? thanks.

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@7studMay 28.2005 — function g(text)
{
alert(text);
}

g("Borussia M'gladbach");
Copy linkTweet thisAlerts:
@iboluiauthorMay 28.2005 — thanks!
Copy linkTweet thisAlerts:
@ExuroMay 28.2005 — As you probably figured out, the problem was just in your function call. First, if you're passing a string into a function, you need to put that string in quotes:test([color=red]"[/color]Borussia M'gladbach[color=red]"[/color]);Next, [i]all attribute values[/i] should be placed inside quotes:
&lt;input type=[color=red]"[/color]checkbox[color=red]"[/color] name=[color=red]"[/color]one[color=red]"[/color] value=[color=red]"[/color]1.00[color=red]"[/color]&gt;Now we run into a bit of a problem. Since we can't really put the function call inside an [FONT=Courier New]onclick[/FONT] event attribute at it is, because it contains quotes too. We can, however, fix this one of two ways:
Use apostrophies around the string instead of quotes within the call to test(),
and escape the interal apostrophe by using a backslash:
&lt;input type="checkbox" name="one" value="1.00" onClick="test('Borussia M'gladbach')" /&gt;
Or, we can use the entity codes for quotation marks instead:
&lt;input type="checkbox" name="one" value="1.00" onClick="test(&amp;#38;#34;Borussia M'gladbach&amp;#38;#34;)" /&gt;
Copy linkTweet thisAlerts:
@CharlesMay 28.2005 — Quotes [i]should[/i] always be used but are not necessary here.

From the HTML 4.01 Specification:In certain cases, authors may specify the value of an attribute without any quotation marks. The attribute value may only contain letters (a-z and A-Z), digits (0-9), hyphens (ASCII decimal 45), periods (ASCII decimal 46), underscores (ASCII decimal 95), and colons (ASCII decimal 58). We recommend using quotation marks even when it is possible to eliminate them.[/quote]
×

Success!

Help @ibolui spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...