?
Solved

how encode a url in java script

Posted on 2011-03-08
17
Medium Priority
?
356 Views
Last Modified: 2012-05-11
Hi ,

I have pass some japness char throw URL in java script and i get values in java . while i am getting junk value only coming ? how can i get the values  correctly?
0
Comment
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
17 Comments
 
LVL 33

Accepted Solution

by:
Big Monty earned 501 total points
ID: 35071678
use the escape function to encode your data:

str = escape( 'this text should be encoded' );
0
 
LVL 20

Author Comment

by:Sathish David Kumar N
ID: 35071792
i got java error

java.io.CharConversionException: isHexDigit like this ?
is there any other way ??
0
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 501 total points
ID: 35075126
>i got java error
>java.io.CharConversionException: isHexDigit like this ?

The code provided by @The_Big_Daddy is javascript not java. You need to test it on the client side.

Else, the best way to handle character encoding problem is to use the same one everywhere and an encoding supporting your characters.
Best is to use UTF8 (database, html page, request, response,...)
Could you confirm you're using the same everywhere ? And which one ?
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 20

Author Comment

by:Sathish David Kumar N
ID: 35079293
ya i changed in java script . while i am taking the values in java its giving this error !!

Ya i am using UTF-8 format only .  
0
 
LVL 82

Expert Comment

by:leakim971
ID: 35083090
>Ya i am using UTF-8 format only .

I follow your other thread as you know, we need to be sure of that
0
 
LVL 2

Assisted Solution

by:cyberhitesh
cyberhitesh earned 498 total points
ID: 35085493
escape() function is the only way to encode string in javascript
0
 
LVL 20

Author Comment

by:Sathish David Kumar N
ID: 35138448
i set some values in popup to parentwindow !!

May be that time char encoding format will change !!

can you tell me how to set the values with UTF-8 format

opener.forName.filedNmae.value="japanesh char";
0
 
LVL 82

Expert Comment

by:leakim971
ID: 35141011
An example :

parent window :


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<head>
<title>http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_26871660.html</title>
<script>
	function openLittle() {
		little = window.open("little.html");
	}
</script>
</head>
<body>
<form name="forName">
<input name="filedNmae" type="text" value="japanese will appear here" style="width:320px;text-align:center" />
<input type="button" value="click to open popup window" onclick="openLittle();" />
</form>
</body>
</html>

Open in new window

0
 
LVL 82

Expert Comment

by:leakim971
ID: 35141025
little.html :


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<head>
<title>http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_26871660.html</title>

</head>
<body>
<form name="littleForm">
<input name="japan" type="text" value="put inside japanese chars and click ok to send them to parent" style="width:400px" />
<input type="button" onclick="window.opener.forName.filedNmae.value=document.littleForm.japan.value" value="OK" />
</form>
</body>
</html>

Open in new window

0
 
LVL 20

Author Comment

by:Sathish David Kumar N
ID: 35141040
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
is this engough ?
0
 
LVL 82

Expert Comment

by:leakim971
ID: 35141072
>is this engough ?  
for two simples HTML pages, yes

...but it seems you get/from data from/to database and so work with server side language
0
 
LVL 20

Author Comment

by:Sathish David Kumar N
ID: 35141215
>>>>>>>>
...but it seems you get/from data from/to database and so work with server side languag
i have set that in java
0
 
LVL 82

Expert Comment

by:leakim971
ID: 35141247
ok so if you "put" the value with the wrong format on the server side, you will not get it in the right format on the client side
0
 
LVL 20

Author Comment

by:Sathish David Kumar N
ID: 35141262
actually my problem is

with form submit i can get the values  (Japanese values) so its set proper char-set format

but with out form submitting like pop up window open(i want to retrieve some values so iam going with that url for popup) so that time my char set is not working.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 35141285
"put" mean something like (line 11 of little) :

out.println("<input name=\"japan\" type=\"text\" value=\"" + ImInWrongFormat + "\" style=\"width:400px\" />");

Open in new window

0
 
LVL 82

Expert Comment

by:leakim971
ID: 35141294
did you tried my two simple html page ? it work fine on your side?
0
 
LVL 20

Author Closing Comment

by:Sathish David Kumar N
ID: 35147959
Thanks for your time. but iused encodeURI() to solve the issue !!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses
Course of the Month10 days, 6 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question