/    Sign up×
Community /Pin to ProfileBookmark

Need help in dealing with % value !

Hi,

I’m facing one issue in passing percentage value in through javascript. Here’s a sample script below.

<html>
<body>
<script language=”JavaScript”>

function call_action_soa(form){
alert(form);
}
</script>
<FORM NAME=”myform” ACTION=”” METHOD=”GET”>
<table>
<tr><td>
<a href=”javascript:call_action_soa(‘PP-asia%54069-061031’)”>PP-asia%54069-061031</a></td>
<td><INPUT TYPE=”button” NAME=”button” Value=”Click” onClick=”javascript:call_action_soa(‘PP-asia%54069-061031’)”>
</td>
</FORM>
</tr>
</table>
</body>
</html>

Here,when I pass the value in href, in javascript function,its getting transformed to ‘PP-asiaT54069-061031’ ie. the ‘%’ is getting replaced by ‘T’. The same think when used from a button doesn’t transform the %.

Any pointer will be highly appreciated.

Thanks

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@CharlesJul 11.2006 — That'll happen - the browser is encoding the value as a URL and you can't really blame it.

The best solution is to not use JavaScript in the "href" atttribute. Us the "onclick" handler instead.
Copy linkTweet thisAlerts:
@phpnoviceJul 11.2006 — ie. the '%' is getting replaced by 'T'.[/QUOTE]
I'm surprised it is not worse than that. I would expect this:

call_action_soa('PP-asia%54069-061031')

to become this:

call_action_soa('PP-asiaT069-061031')

The reason is that %54 is the url-encoding for the letter "T".

So, Charles' answer is the correct one -- use [b]onclick[/b]
Copy linkTweet thisAlerts:
@shamik12authorJul 11.2006 — Irony is, the application is designed to use a hyperlink instead of a button,I've little choice there...
Copy linkTweet thisAlerts:
@phpnoviceJul 11.2006 — [b]onclick[/b] works in a hyperlink, too. ?
Copy linkTweet thisAlerts:
@shamik12authorJul 11.2006 — Thnx a lot phpnovice ..... onclick on href worked like a charm....

appreciate ur help...
Copy linkTweet thisAlerts:
@phpnoviceJul 11.2006 — Thnx a lot phpnovice [/QUOTE]
...and Charles.

You're welcome.

Cheers.
×

Success!

Help @shamik12 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.20,
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,
)...