Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Sep 2002
    Posts
    60
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question JavaScript + ASP

    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):
    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

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,048
    Thanks
    0
    Thanked 251 Times in 247 Posts
    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.

    Code:
    <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>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •