cgi|javascript|js| Tutorial
Use JavaScript instead of CGI
You might be familiar with CGI scripts, and you can use CGI to pass numbers or variables from one page to another on a form. Of course, you can use "POST" to pass a variable to a separate thread without appearing in the browser, or to encode the variable to a URL using "get".
JavaScript cannot use the Post method when a variable is processed on the server side, but you can note that when you submit a form using the Get method, the Anchor bar contains additional information after the file name, such as:
Www.pconline.com.cn/mypage.html?name=Mike&age=33
Using JavaScript We can access these variables, which can be implemented using a combination of related numbers, as follows:
<script language= "javascript1.1" >
<!--Hide from older browsers
function Forminput () {
Empty Object
}
var valueof = new Forminput ();
var pairs = document.location.search.substring (1). Split ("&");
for (Var i=0 i < pairs.length; i++) {
var values = pairs[i].split ("=");
Valueof[values[0]] = unescape (values[1]);
}
Stop hiding-->
</SCRIPT>
The purpose of the above code is to extract the variables from the browser's locator bar and store them in a related combination of numbers. In other parts of the page, any variable can be referenced like this: valueof["VariableName", of course, in the script tag.
As a test, we can use for. The In loop Loop statement lists all the variables that are passed. This allows us to loop over the contents of all the relevant arrays, regardless of whether we are not until the names of these variables. The specific code is as follows:
<script language= "JavaScript" >
<!--Hide from older browsers
for (var x in valueof) {
document.write (x + "=" + valueof[x] + "<br>");
}
Stop hiding-->
</SCRIPT>
This time you will enter the following content:
Name=mike
Age=33
This example is useless, but it's just to show you how the program works. These variables can now be used to populate the contents of a form element, or to display a picture or create other Web content, in short, to achieve what CGI can achieve.