HTML — Javascript scripts
JavaScript and Vbscript are often used in an HTML page code to give more interactivity to the page, or just for one of the many applications of these scripts.
Using these scripts you can create interactive animations for images, animated menus with amazing effects, and so on. Also, one of the most important applications is that of validating a form before sending it. This will make the user spend considerably less time in the case the user has wrongly completed the fields, and a reload of the page being needed.
In this part we will only talk about the method of inserting the script into HTML
Note: Most of the time it is much easier to just download from the internet than to write these scripts. Of course, that is possible only if the author has given his/her agreement for personal and/or commercial use. There are also a variety of javascript libraries that are free to use.
Inserting JavaScript in HTML
Inserting a javascript code is done very easily using the script tag. Here is an example:
html
For the javascript codes the ‘text/javascript‘ value will be given to the type attribute.
Inserting Vbscript in HTML
Inserting a VBScript code is done in the same way as the javascript code is done, only that you replace the ‘text/javascript’ with ‘text/vbscript’. Here is the example:
html
It is always recommended to insert a comment along with the javascript and VBScript codes. That will warn the browsers that do not support that kind of script or browsers that have javascript and VBScript disabled.
HTA: синхронизация VBScript и JavaScript
Можно совместно использовать VBScript и JavaScript в одном HTA(HTML) документе.
Вызов функции JavaScript из области VBScript осуществляется достаточно просто:
Вызов функции VBScript из области JavaScript осуществляется несколько сложнее, путем передачи VBScript-функции как параметра.
Пользуясь методом window.close() и тем, что скрипт общей области HTA(HTML) документа выполняется до отображения окна, можно пробовать создавать неоконные HTA проекты, с одновременным использованием VB и JavaScript(некий аналог .WSF). Например в JavaScript отсутствует функция Hex, зато такая функция есть в VBScript. Пользуясь вышеприведенными соображениями, можно получить Hex представление числа из области JavaScript:
Using VBScript in HTML document
We have read in the ‘ Learn basics of the VBScript‘ that the VBScript can be used as client scripting( In Internet Explorer browser) as well as server scripting(IIS). In this article I’ll explain you how we can use the VbScript as client scripting.
You can use the script element to add VBScript code to an HTML page.Let’s suppose a simple html document. The following example uses a html input element of type button. For the click event of the this button example use the Button1_OnClick() procedure.
See the procedure name Button1_OnClick that contains the element id and event name separated with underscore(_).
Let’s see the another example to see that how to access the value of the input text type element. Make some small changes in above example like as:
In the example we access the entered text into the input text type control with the help of Value property. So it is the important to have some knowledge of the events and properties of the html elements. I am writing down the list of the few:
input element( type button)
Properties: Enabled, Name, Value
input element( type text)
Events: OnFocus, OnBlur, OnChange, OnSelect
Properties: Enabled, Name, Value,DefaultValue
input element(type radio)
Properties: Enabled, Name, Value, Checked
select element
Events: OnFocus, OnBlur, OnChange
Properties: Name, Length, Options, SelectedIndex
Add the above html elements in your web page and try to use their events and properties.
Related Posts
- Learn basics of the VBScript – The VbScript Tutorial
- Get the element of the parent window from the iframe in jQuery
- Set the src attribute of the iframe element using jQuery
- Bind the html select control from the comma separated string in JavaScript
- Code snippet: Create a new row in the HTML table using jQuery
- JavaScript Introduction
- Simple Jquery fadeOut
- Data types, Variables and Array in VBScript
- HTML select element and jQuery
- How to know whether string contains special characters or not in JavaScript