0
votes

I have this code which contains mixed VBScript and HTML:

IF (x.name="name") THEN
    n=x.value
    response.write("<tr>")
    response.write("<th>Name:</th>")
    response.write("<td><input name=""n2"" value=" & n & "></input></td>")
    response.write("</tr>")
'...

and I want the to use the content of the input tag inside VBScript in the same file.

I tried this:

   <% dim name
   name=request.form("n2")%>

but when I tried printing it using Response.Write it will be empty which means it didn't take the current content in the form field.

How to get it in VBScript while being in the same page?

1
This is not mixed VBScript and HTML, it's pure classic ASP written with VBScript that sends HTML to the browser. - Shadow Wizard Is Vaccinated V3

1 Answers

1
votes

If you want to access data using Request.Form you need to POST the contents of the input field back to the same page.

response.write("<form method=""post"" action=""yourpage.asp"">")
response.write("<table>")
response.write("<tr>")
response.write("<th>Name:</th>")
response.write("<td><input type=""text"" name=""n2"" value=""" & n & """/></td>")
response.write("</table>")
response.write("<input type=""submit"" value=""Submit"" name=""submit""/>")
response.write("</form>")

Then you can use Request.Form to get the request contents of the form post. The Form collection retrieves the values of form elements posted to the HTTP request body, with a form using the POST method.

Dim name
name = Request.Form("n2")
response.write("name")