...

View Full Version : JavaScript + ASP



arpan_de
05-15-2007, 01:21 AM
A ASP page has a HTML Form which has a dropdown select list & a textbox. Assume that the dropdown select list lists 4 options - 0A, 1B, 2C & 3D. The value of these 4 options is the same as 0A, 1B, 2C & 3D resoectiveky.

When a user selects an option from the dropdown select list for which I have used the following onChange JavaScript event function of the dropdown select list:code (the code makes use of both JavaScript & ASP This is the ASP code):

<%
'this is the ASP code
If(Request.ServerVariables("REQUEST_METHOD")="POST") Then
Dim str
str=Request.Form("hdn")
%>
<script language="JavaScript">
var str1="<%= str %>"
document.forms[0].hdn.value=str1
</script>
<%
End If
%>
but the textbox doesn't get populated with the value after the form is posted but if the document.forms[0].hdn.value=str1 is replaced by, say, an alert message like this

alert(str1)

then the alert box correctly displays the input Form data that a user entered in the textbox just before the Form was posted.

Can someone please tell me how do I populate the textbox with the value of a ASP variable?

Thanks,

Arpan

glenngv
05-15-2007, 01:49 AM
You said you are using an onchange function but I didn't see it in your post.

But to populate the textbox, the javascript code should be be below the textbox because javascript cannot access a field that has not loaded yet.


<form>
<%
'this is the ASP code
If(Request.ServerVariables("REQUEST_METHOD")="POST") Then
Dim str
str=Request.Form("hdn")
%>
<input type="text" name="hdn" />
<script language="JavaScript">
var str1="<%= str %>"
document.forms[0].hdn.value=str1
</script>
<%
End If
%>
</form>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum