Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP + JavaScript

Status
Not open for further replies.

PepperPepsi

Programmer
Aug 3, 2000
241
0
0
US
Hi,<br>is there any way i can call a javascript variable into ASP?<br><br>for example <br>i have <br>&lt;SCRIPT LANGUAGE=&quot;JAVASCRIPT&quot;&gt;<br>var js_temp<br>js_temp = &quot;hello&quot;<br>&lt;/script&gt;<br>&lt;%<br>dim asp_temp<br>%&gt;<br>and i want the variable js_temp store into asp_temp<br>so that the asp_temp will have &quot;hello&quot; as the result<br>i only know how to do it from ASP to Javascript <br>see below example<br>&lt;%<br>dim asp_temp<br>asp_temp = &quot;hello&quot;<br>%&gt;<br>&lt;SCRIPT LANGUAGE=&quot;JAVASCRIPT&quot;&gt;<br>var js_temp<br>js_temp = &lt;&=asp_temp%&gt;<br>&lt;/script&gt;<br><br>thanks<br>Pepsss<br>
 
There is no way to turn Javascript to ASP. Javascript is executed on the client's machine. ASP is executed on the server before the client get's the page. <br><br>The only way to send Javascript information to an asp page is using the post or get method and requesting the same page again.<br>
 
Your question would be better phrased as:<br>Can I set a variable in the server code from the client?<br><br>The reason for this is that both server and client code can be written in either Javascript or VBscript. Additionally, server script in ASP pages can be in Perl, PHP, or any other scripting language that is made known to the IIS server.&nbsp;&nbsp;Granted,&nbsp;&nbsp;usually,&nbsp;&nbsp;the server side code is written in VBScript, while the client code is usually Javascript,&nbsp;&nbsp;but this doesn't have to be the case.<br><br>To send a value to a serve script from the client, you can use a form, querystring, or cookie. <p>nick bulka<br><a href=mailto: > </a><br><a href= > </a><br>
 
Sending a variable from javascript on the client to asp on the server would mean you would have to send a page request. Javascript on the client operates in the context of a loaded page in a browser. Asp on the server operates in the context of a request to the server. They can't operate simultaneously (unless you want to get into java RMI or something but then you're in the wrong forum).<br><br>Here is an example suggestion.<br><br>suppose you have some javascript which sets up a prompt window where the user enters a number then a javascript function calculates some value on the user input. Then suppose you want to get the resulting value, contained in a javascript variable, to an asp script which then inserts it in a database or whatever:<br><br>HTML PAGE<br>------------------------------------<br><font color=red>&lt;script language=javascript&gt;<br>function calculate()<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;var userinput = prompt(&quot;please enter a value&quot;,&quot;&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;if (userinput)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (isNaN(userinput)) <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert(&quot;Input must be a numeric value.&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;userinput = parseInt(userinput,10);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;userinput += 5;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;location=&quot;targetpage.asp?value=&quot;+escape(userinput);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&lt;/script&gt; <br><br>&lt;a href=&quot;javascript: calculate();&quot;&gt;click here&lt;/a&gt;</font><br><br><br>RECEIVING ASP PAGE:<br>--------------------------------<br><font color=red>userinput = request.querystring(&quot;value&quot;)</font><br>etc. <p>--Will Duty<br><a href=mailto:wduty@radicalfringe.com>wduty@radicalfringe.com</a><br><a href= > </a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top