Asp JavaScript 教程 - Lesson 03 The new String( ) Constructor

转载 2006年06月24日 13:34:00

The new String( ) constructor

Get Started:

new String( ) is another strange place to go early on the lesson plan. But just like Escape Characters, new String ( ) is vital to successful ASP JavaScript applications. Below are two scripts for Lesson 03.

//No ASP Here, just a regular HTML Page
<STRONG>Type something into the text box and submit it.</STRONG>
<FORM ACTION="script03a.asp" METHOD="Post">
<INPUT TYPE="Text" NAME="WebPageVariable"><BR>
<STRONG>How Much Money do you make each month?</STRONG><BR>
<SELECT NAME="monthlySalary">
<OPTION>Under $5,000,000</OPTION>
<OPTION>Above $5,000,000</OPTION>
<OPTION>Nobody's darn business</OPTION>
<INPUT TYPE="Submit" VALUE="Submit">

Click Here to run the script in a new window.

Below is the actual ASP Script that does the heavy lifting.


var WebPageVariable = new String( Request.Form("WebPageVariable") )
WebPageVariable = WebPageVariable.toUpperCase();

var monthlySalary = new String( Request.Form("monthlySalary") )
monthlySalary = monthlySalary.toLowerCase();

Response.Write("The Web Page Variable you typed is: ");
Response.Write(WebPageVariable + "<BR>/r");
Response.Write("The monthly salary you listed is: " + monthlySalary + "<BR>/r");


new String( ) in Action:

Now check out the ASP lines below.

var monthlySalary = new String( Request.Form("monthlySalary") )
monthlySalary = monthlySalary.toLowerCase();

Request.Form gets its own lesson later on. Here's the point of showing it to you now. The data held in Request.Form (which ultimately comes from the user) is not a JavaScript data type. Instead, it is a native ASP data type. JavaScript cannot manipulate ASP data types.

The solution is cast the ASP data type into a JavaScript data type. In this case, the way to do that is the new String( ) constructor.

Quick Note:

If all you want to do is redirect the text from Request.Form back out to the user, then you don't need new String( ). But if you need to act upon the text with a JavaScript Function or Method, then you will need new String( ).

Without new String( ):

Take a look at the line I printed below.

var WebPageVariable = Request.Form("WebPageVaraible").toUpperCase(); 

ERROR! The Line Above Will Throw An Error because Request.Form("WebPageVaraible") is an ASP Object, and toUpperCase( ) is a JavaScript method.

Microsoft JScript runtime error '800a01b6'

Object doesn't support this property or method

/asp/Section01/script03b.asp, line 9

Moving Forward:

Now that we have Escape Characters and new String( ), everything else we want to do in ASP JavaScript becomes a lot easier.

You ain't seen nothing yet. We can mix and match JavaScript functions and methods with VBScript functions and methods. VBScript and JavaScript functions can pass arguments back and forth. They work wonderfully together. That will be the subject of lesson 04.

The constructor SimpleAdapter(new View.OnClickListener(){},...)is undefined的问题及解决

  • KiddWon
  • KiddWon
  • 2015年08月06日 20:13
  • 997

The constructor SimpleAdapter(new View.OnClickListener(){}, List<Map<String,Object>>, ..的解决方法

  • KiddWon
  • KiddWon
  • 2015年08月06日 20:30
  • 898


Performance关于代码性能相关方面的   序号 Description 备注 1. Bx: Primitive value is boxed and then ...
  • u013531824
  • u013531824
  • 2016年05月09日 17:12
  • 1546

The constructor Date() is undefined问题的处理

在写下面代码的时候: import java.sql.Date; import java.text.SimpleDateFormat; public class TimeDemo { publi...
  • shirui8653719
  • shirui8653719
  • 2013年08月10日 09:02
  • 3316

The constructor Job(Configuration,String) is deprecated

  • chiclewu
  • chiclewu
  • 2014年10月27日 15:24
  • 5096

Asp JavaScript 教程 - Lesson 02 Escape Characters

 Escape CharactersNot Out of Place: The instruction of Escape Characters in Lesson 02 seems out of p...
  • cnsdybj
  • cnsdybj
  • 2006年06月24日 13:16
  • 905

The constructor ActionEnter(HttpServletRequest, String) is undefined

平常我们在用ueditor的时候,导入ueditor文件夹或者从别人那里扒拉来的代码,发现会报以下的错误,其错误如下:The constructor ActionEnter(HttpServletRe...
  • liliang_11676
  • liliang_11676
  • 2018年02月08日 14:22
  • 24

兔子--The constructor AlertDialog.Builder(new View.OnClickListener(){}) is undefined

出错原因:Builder builder=new Builder(this) 该方法里面的this为当前类OnClickListener的实例, 而不是我们想要赋值的MainActivity.thi...
  • u013425527
  • u013425527
  • 2014年11月30日 15:02
  • 3909

报错The constructor worker(int, String, float) is undefined

请教下高手,这个报错The constructor worker(int, String, float) is undefined是怎么回事啊 2011-08-31 10:21南华真人大弟子 |...
  • evilcry2012
  • evilcry2012
  • 2015年11月03日 15:22
  • 1641


enum这个关键字在java中既熟悉又陌生,因为很少用它。其实enum的功能完全可以用其他方式实现,不过对它的原理 还是不太清楚。下面开始研究。 写个简单的例子: package org.t...
  • lushuaiyin
  • lushuaiyin
  • 2013年03月25日 21:21
  • 1547
您举报文章:Asp JavaScript 教程 - Lesson 03 The new String( ) Constructor