Masatoshi Natsume COMS 463 Jscript.NET Jscript.NET is a current version of Jscript. It is compatible with previous version of Jscript and supports .NET Framework, which is a software development platform for the network base applications. .NET is platform independent, and the device supported by .NET runs the software like the Java virtual machine so that the device can have services without depending on platforms. Jscript is a Script language which is developed by Microsoft. originally comes from JavaScript which is developed by It is Netscape Communication and Sun Microsystems, and Microsoft extended it to Jscript. Those extensions include file operation functions and other functions to call and use Component Object Models (COM). and it can be run by Internet Explorer. Jscript can be embedded in HTML, Also, Jscript can be used to create Web pages dynamically by using the Web server, Internet Information Server (IIS),. On of the big difference between Jscript.NET and JavaScript or Jscript is that although all of them are script languages, Jscript.NET needs to be compiled to run. Thus, the performance is better than JavaScript or Jscript. Jscript is often compared with VBScript. Both of them are very popular script language for Windows, but the main deference is the grammar. The grammar of VBScript is close to BASIC or Pascal, but Jscript is close to C/C++/Java. However, everything could be done by VBScript could also be done by Jscript. However, Jscript.NET is not popular for Web programming, so I focused Jscript part of Jscript.NET. Declare Jscript First, Jscript needs to be declared inside HTML. <html> <head> <title>Sample</title> </head> <body> <script language=”Jscript”> [Program code] </script> </body> </html> Hello World!! Then, add code inside that. Following code prints out “Hello World!!” with local date and time. <script language=”Jscript”> dd = new Date(); document.write(dd.toLocaleString()); document.write("<br>"); document.write("Hello World!!"); </script> Document.write is like Response.write in ASP, and toLocaleString() on the third line is the method to get the local date and time. Loading Script File The script can be also loaded from other files. of loading script code from a file called function.js. Following is the example <script language="Jscript" src="function.js"> Text Field Next example allows us to read the value from a text field. In this example, when user clicks the button an alert will be prompted with the value that used input. If nothing was entered in the text field, it alerts the empty input. However, the most important thing in this example is using of the function. The function is like a method of Java, so processes are organized to build a function. In this example, the action of clicking the button is organized as a function called “check()”. Usually, functions are declared inside the head part of HTML code so that those functions will be loaded when the page is loaded. In line 19, you will see “onClick”, which is an action of mouse, and there are many kinds of actions, such as “onFblClick” for double click action, “onMouseUp” for the up action of click, “onMouseDown” for the down action of click, “onMouseOver” for just the mouse cursor points the button, and so on. <html> <head> <title>Text Filed</title> <script Language="Jscript"> function check() { txt = document.myFORM.myTEXT.value; if (txt == ""){ alert("Text field is empty"); }else{ alert("Entered: " + txt) } } </script> </head> <body> <form name="myFORM"> <input type="text" name="myTEXT"> <input type="button" onClick="check()" value="Check"> </form> </body> </html> Radio Button This example returns the value of the selected radio button. Every time radio button is selected the function rdo_Change(obj) will be called, and get the value of selected radio button. Then, when the Check button is clicked the value obtained by rdo_Change(obj) function will be prompted. Also, I used “onDblClick” mouse action instead of regular ”onClick” action so that the user need to double click the button to get the response. <html> <head> <title>Radio Button</title> <script language="Jscript"> var msg; function rdo_Change(obj){ msg = obj.value; } function func3(obj){ alert("My favorite fruit is " + msg); } </script> <form name=frm3> Please select your favorite fruits<br><br> <input type="radio" name="rdo1" value="Apple" onClick=rdo_Change(this)>Apple<br> <input type="radio" name="rdo1" value="Banana" onClick=rdo_Change(this)>Banana<br> <input type="radio" name="rdo1" value="Pineapple" onClick=rdo_Change(this)>Pineapple<br> <input type="radio" name="rdo1" value="Orange" onClick=rdo_Change(this)>Orange<br><br> <input type="button" value="Check" onDblClick=func3(rdo1)><br> </form> </body> </html> Check Box In this example, when user clicks the Check button the number of selected check boxes and the status of each check box will be reported. Each time user click the Check button, func5() will be called, and count the number of selected check boxes by using the for loop. In side the for loop, you will see “document.frm5.element.length” returns which returns a total number of controls. In this case, it includes the button, so the returned number will be 5. Also, “document.frm5.elements[i].checked” returns a Boolean whether the check box is selected or not. <html> <head> <title>Check BOx</title> <script language="Jscript"> function func5(){ var cnt=0; var i; for (i =0; i< document.frm5.elements.length;i++){ if(document.frm5.elements[i].checked) cnt++; } alert (cnt + " CheckBoxes are selected" + "¥n" + "CheckBox1 checked: " + document.frm5.elements[0].checked + "¥n" + "CheckBox2 checked: " + document.frm5.elements[1].checked + "¥n" + "CheckBox3 checked: " + document.frm5.elements[2].checked + "¥n" + "CheckBox4 checked: " + document.frm5.elements[3].checked); } </script> <form name=frm5> <input type=checkbox name=chk1>Check1<br> <input type=checkbox name=chk2>Check2<br> <input type=checkbox name=chk3>Check3<br> <input type=checkbox name=chk4>Check4<br><br> <input type=button value="Check" onClick=func5()> </form> </body> </html> Conclusion Jscript.NET is easy to learn like VB.NET, and if the learner has already known Java like us, it’s much easier to learn. Moreover, it has higher performance, so there might be a situation that we need to use Jscript.NET instead of VB.NET or JavaScript. Although the compatibility with JavaScript is not perfect, most of important part is standardized as ECMA (European Computer Manufacturer Association). In addition, the customized functions that only Jscript has are attractive to get star learning Jscript.NET. Shot Answers 1. What is the difference between JavaScript and Jscript? Microsoft extended JavaScript by adding file operation functions and COM 2. What is the biggest difference between Jscript.NET and Jscript? And what is the advantage or disadvantage of the difference? The biggest difference between Jscript.NET and Jscript is that although both are script language, Jscript.NET needs to be compiled to run. The advantage of the compiling is the better performance. 3. What is the function? The function is like a method of Java, so processes are organized to build a function. 4. What is the main difference between Jscript.NET and VB.NET? Grammar. Jscript.NET is similar to Java, and VB.NET is similar to BASIC. 5. What is the toLocaleString()? the method to get the local date and time Multiple Choices 6. Where does the function usually be written? 1. title 2. head 3.body 2.head 7. Which control Jscript can have 1.textfield 2.radio button 3.check box 4. all 4.all, Jscript can use all of them 8. document.frm5.elements[0].checked returns 1.true 2. false 3.boolean 3.boolean 9. What is the value of elements.length in following example? a. 2 b.3 c.4 <html> <head> <title>Check Box</title> <script language="Jscript"> function func5(){ var cnt=0; var i; for (i =0; i< document.frm5.elements.length;i++){ if(document.frm5.elements[i].checked) cnt++; } alert (cnt + " CheckBoxes are selected" + "¥n" + "CheckBox1 checked: " + document.frm5.elements[0].checked + "¥n" + "CheckBox2 checked: " + document.frm5.elements[1].checked); } </script> <form name=frm5> <input type=checkbox name=chk1>Check1<br> <input type=checkbox name=chk2>Check2<br><br> <input type=button value="Check" onClick=func5()> </form> </body> </html> b.3 10. which has the highest performance? 1.VB.NET 2.JavaScript 3.Jscript.NET 3.Jscript.NET Fill in 11. Internet Information Server (IIS) is the ____________ that can be used to create Web pages dynamically. Web server 12. ____________ is a control that will be called only when the button is double clicked. OnDblClick 13. the element.length returns ____________________. The number of controls 14. document.write is a similar function to _____________ in ASP. response.write 15. _________ is a dialogue that let the user know some information with small window and beep sound. alert