China&boy A detailed study of how VBScript and JavaScript pass variables! (including server side and client)

Source: Internet
Author: User
Tags error handling execution html form variables regular expression visual studio
vbscript| Variable | server | Client about VBScript and JavaScript how to pass variables (both server side and client)

A: Recently, often encountered a netizen asked, how to make VBScript and Javascipt pass variables. I don't know why I'm doing this. Because almost every scripting language can do what is needed

Function. Why do we need two together? However, we can tell you. It's perfectly OK. Below, about why can the concept, yesterday I spoke for half a day, still have netizen do not understand. At last

It's getting me all confused. So let's just combine the examples.
1:vbscript and Javascipt transfer variables (client)
<HTML>
<HEAD>
<meta Name=vi60_defaultclientscript content=javascript>
<script language=vbscript>
<!--
Dim strtemp ' First, we're here to define a variable in VBScript
Strtemp=10 ' Then, here gives it a negative value.
-->
</SCRIPT>

<meta name= "generator" content= "Microsoft Visual Studio 6.0" >

<script Id=clienteventhandlersjs language=javascript>
<!--

function Document_onclick () {
Window.alert (strtemp); /** here, we can simply use the volume in VBScript just without a definition. **/
}

-->
</SCRIPT>
<script Language=javascript for=document event=onclick>
<!--
Document_onclick ()/** At this point, you can see that the variables in VBScript are already coming through by clicking on the page. **/
-->
</SCRIPT>
</HEAD>
<BODY>

Description: In fact, if you define a variable in VBScript. If it is not in the function or in the process, he is a global variable. This whole situation is from now to the end of the Web page execution

。 So, you can use it directly in JavaScript. But here you have to be aware of the order. The script execution process is interpreted on a line-by-row basis if you put the part of the variable in the VBSCIRPT

After JavaScript, you may not get the correct result. The truth is very clear.
2:javascript and VBScript pass variables (client)
In fact, this should not be said, it can be. But let's give a simple example. I can see it by myself.
Html>
<HEAD>
<meta Name=vi60_defaultclientscript content=javascript>
<script language=javascript>
var strtemp=10;
</script>

<script language=vbscript>
MsgBox (strtemp)
</script>

</HEAD>
<BODY>

3: The server side and the client pass variables.
First of all, I would like to say that server-side and client script can be transmitted. Don't care what you preach. However, the server-side and the client pass variables are not the same as what is said above. or not called

Passing variables. Let's just combine the examples.
<%@ Language=vbscript%>
<%
Dim strIp
Strip=request.servervariables ("REMOTE_ADDR")
Response.Write "Your IP is:" &strip
%>
<body>
<script language=vbscript>
<!--
MsgBox (strIp) ' Please note: this is wrong!
-->
</SCRIPT>
</body>
If you finish the sentence above, you may not get an error. But the answer is wrong. The reason is that I said, this is not possible in the variable passed over. If we make the process clear, we won't make this.

Kind of mistake.
First, the server side first interprets the <%%> direct code. If so, explain it to the client after it has been executed, and the value is sent directly to the HTML form. As for client script, dress

The end of the service will not move and throw it over. So let's look at the example above. The client's script is not interpreted by the server side. and the server-side script has been converted to a fixed value, so,

There's nothing in the strip. So you don't get the answer you want.
So how do we get the IP address over? This is going to move a little bit of brain, in fact, do not move. Oh. Change the MsgBox (strIp) directly to this.
MsgBox ("<%=strIp%>") is OK. Note that the "" number is added, because at this point the strip has been interpreted as a string.
See here, I believe we all understand that the server side and the client strictly, it is impossible to pass variables. However, the values can be modified. (called not to call the value, do not care about him, anyway has been

To the correct answer. As for the client's JavaScript can pass the value. I don't say you understand. Of course.

Two: In the final words, VBScript and JavaScript function in the scripting language. Can't say who is good who is bad, probably in VBScript the mistake handles a few better. JavaScript in Word

String processing is better, but with the introduction of the regular expression in VBScript, the error handling in JavaScript is increasing. So, I think it's all OK with that one. The key is to see your learning

Habits and hobbies, say these reasons if you can do with one, it is best not to use another. Because it's the best in terms of speed and efficiency. Because browsers do not have to call both

Two explanations of the engine. Of course the speed is fast.
(Full text, I hope to bring some friends to help!) )






Related Article

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.