How do I get the Request.Form
within a script tag?
<script language="javascript" type="text/javascript">
var sLandingPage = "";
var sInitContent = "" + Request.Form("textarea") + "";
var sInitDialogMsg = "";
</script>
You can't do request.form in javascript. But you can get things out of the query string if you post the form via get.
To read an url parameter from javascript you could use the following method:
<script type="text/javascript">
var sLandingPage = '';
var sInitContent = getUrlParam('textarea');
var sInitDialogMsg = '';
function getUrlParam(name)
{
name = name.replace(/[\[]/, '\\\[').replace(/[\]]/, '\\\]');
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec(window.location.href);
if(results == null)
return '';
else
return results[1];
}
</script>
Javascript is running at client side, so if your want to get the text area's value before post your page to serve, use this :
var sInitContent = document.getElementById("textarea");
but if you want to get the posted value of your textarea, (I'm assuming you're using asp or asp.net) try this :
var sInitContent = '<%= Request.Form("textarea")%>';
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.