0

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. Commented Jun 18, 2014 at 8:06

1 Answer 1

0

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")
Sign up to request clarification or add additional context in comments.

2 Comments

i tried this but didn't work at all it will get me an empty string.. another solution please ?
thank you so much worked perfectly, i didn't put the submit button after i did everything worked perfect. thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.