Thursday, July 9, 2009

I have some Javascript and ASP in a webpage. How do I pass a Javascript variable to ASP (read below)?

Essentially I have a variable named "strfile" that is in Javascript. I need to access this variable or "make it available to be used" by ASP. The Javascript and ASP code is all in the same page.

I have some Javascript and ASP in a webpage. How do I pass a Javascript variable to ASP (read below)?
The easiest way is to set the value of the JavaScript variable to a hidden input field.





%26lt;input type="hidden" name="strfile" id="strfile" /%26gt;





Then in your JavaScript, simply say:





document.getElementById ('strfile').value = strfile;





When you submit the form, the page that receives the submit action (could be the same or a different page), the strfile variable will be available in ASP as request.form("strfile")
Reply:Maybe this could give you a hint.





To get the whole query string:





%26lt;%


the_name = Request.QueryString() ' Your var value


%%26gt;


%26lt;script language="javascript"%26gt;


var the_name = ""


%26lt;/script%26gt;


%26lt;%


Dim the_name


the_name = Request.QueryString()


Response.write("the name is " %26amp; the_name)


Response.write("%26lt;script%26gt;the_name=""" %26amp; the_name %26amp; """;%26lt;/script%26gt;")


%%26gt;


%26lt;script language="javascript"%26gt;


alert(the_name)


%26lt;/script%26gt;





Hope this helps.


No comments:

Post a Comment