Javascript error handling of "hexadecimal numbers missing"

Source: Internet
Author: User
Problem:

I plan to use the preceding statement to write the connection string of the database to the connstr text box on the upper-level webpage. However, during execution, ie reports that the hexadecimal number is missing ".

The Code is as follows:
A = "provider = Microsoft. Jet. oledb.4.0; Data Source = E:/Website Design/Dianming/upload/student. mdb ;"
Response. Write ("<SCRIPT> ")
Html = "parent.doc ument. getelementbyid (" "connstr" "). value =" "+ A + """"
Response. Write (HTML + ";")
Response. Write ("</SCRIPT> ")

Problem Analysis:

What is going on? It is found that the problem lies in the "/" in the string a. In JavaScript, "/" is a special character and needs to be converted in many cases, for this reason, I will use "/" temporary substitution "/" and convert it back when using this string.
The code is rewritten as follows:

A = "provider = Microsoft. Jet. oledb.4.0; Data Source = E:/Website Design/Dianming/upload/student. mdb ;"
Html = HTML + Replace (a, "/", "/") + """"

Response. Write ("<SCRIPT> ")
Html = "parent.doc ument. getelementbyid (" "connstr" "). value =" "+ A + """"
Response. Write (HTML + ";")
Response. Write ("</SCRIPT> ")

Refer:
Example program:

* Encode for HTML.
*/
Public static string htmlencoder (string Str)
{
If (STR = NULL | Str. Equals (""))
Return "";
String res_str;
Res_str = strreplace (STR, "&", "& amp ;");
Res_str = strreplace (STR, "", "& nbsp ;");
Res_str = strreplace (STR, "<", "& lt ;");
Res_str = strreplace (STR, ">", "& RT ;");
Res_str = strreplace (STR, "/" "," & quot ;");
Res_str = strreplace (STR, "'", "& #039 ;");
Return res_str;
}

/**
* Encode for HTML-text.
*/
Public static string htmltextencoder (string Str)
{
If (STR = NULL | Str. Equals (""))
Return "";
String res_str;
Res_str = strreplace (STR, "&", "& amp ;");
Res_str = strreplace (STR, "<", "& lt ;");
Res_str = strreplace (STR, ">", "& RT ;");
Res_str = strreplace (STR, "/" "," & quot ;");
Res_str = strreplace (STR, "'", "& #039 ;");
Res_str = strreplace (STR, "", "& nbsp ;");
Res_str = strreplace (STR, "/R/N", "<br/> ");
Res_str = strreplace (STR, "/R", "<br/> ");
Res_str = strreplace (STR, "/N", "<br/> ");
Return res_str;
}

/**
* Encode for URL.
*/
Public static string urlencoder (string Str ){
Return java.net. urlencoder. encode (STR );
}

/**
* Encode for XML.
*/
Public static string xmlencoder (string Str)
{
If (STR = NULL | Str. Equals (""))
Return "";
String res_str;
Res_str = strreplace (STR, "&", "& amp ;");
Res_str = strreplace (res_str, "<", "& lt ;");
Res_str = strreplace (res_str, ">", "& gt ;");
Res_str = strreplace (res_str, "/" "," & quot ;");
Res_str = strreplace (res_str, "/'", "& acute ;");
Return res_str;
}

/**
* Encode for SQL.
*/
Public static string sqlencoder (string Str)
{
If (STR = NULL | Str. Equals (""))
Return "";
String res_str;
Res_str = strreplace (STR ,"'","''");
Return res_str;
}

/**
* Encode for JavaScript.
*/
Public static string jsencoder (string Str)
{
If (STR = NULL | Str. Equals (""))
Return "";
String res_str;
Res_str = strreplace (STR ,"'","//'");
Res_str = strreplace (STR ,"/"","///"");
Res_str = strreplace (STR, "/R/N", "// n ");
Res_str = strreplace (STR, "/N", "// n ");
Res_str = strreplace (STR, "/R", "// n ");
Return res_str;
}

Html = HTML + Replace (table_list (fileext, path, 2), "/", "/") + """"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.