วันพุธที่ 18 มิถุนายน พ.ศ. 2557

Thread: How to pass a value from javascript to ASP

Code:
<script type="text/javascript">
<!--
function getWidthAndHeight()
{
    var h = screen.height;
    var w = screen.width;
    document.forms[0].widthheightfield.value = h + "," + w;
}
window.onload = getWidthAndHeight;
// -->
</script>

<form ...blah blah>
<input type="hidden" name="widthheightfield" value="">
</form>
That's one way, in which you would receive, for instance "1024,768"... IF you are requesting a value like:

Request.Form("widthheightfield")

on the page you post to.

Of course the solution depends on what you're trying to do exactly, and where exactly in the process you're trying to do it. In order for us to help you in this instance, you're going to have to be a lot more specific.

What exactly are you trying to accomplish, and in what part of your processing?



อีก หนึ่งบทความ
Here's something I've written about this server side / client side confusion that hopefully might shed a little more light. But I like whammy's solution of using JavaScript to fill a hidden field.

So here's a little more info about mixing server-side ASP (which gets processed first) with client-side JavaScript.

It's easy to use the value of a VBScript variable in JavaScript
document.writeln('<%= MyVBScriptVariable %>'); 

Or here is an example which puts the value of a VBScript variable into a JavaScript alert box:
Response.Write "<script language='JavaScript'>alert('The value is " & MyVBScriptVariable & "');</script>"

But to send the value of a JavaScript variable to VBScript, well that's another story. You could have the JavaScript fill in a hidden form field and then post the form. That way VBScript can pick up the value of the hidden form field with Request.Form("MyFieldName")

ไม่มีความคิดเห็น:

แสดงความคิดเห็น