how to use Request.Form("fieldname")?

R

Rich

Hi,

I was experimenting with some basic sample asp code but can't get it to work
correctly:

this is bgselector.asp which works OK - you add the name of a basic color
like blue, green, yellow and call another asp called backcolor.asp where I
have the problem:

bgselector.asp
---------------------------------
<html>
<head>
<title>Test page</title>
</head>
<body>
form>
Background Color selector
<form action ="backcolor.asp" method="post">
Please type in a valid color e.g blue , green , yellow
<input type="text" name ="backcolor"><p>
<input type="submit" value="submit"><p>
</form>
</body>
</html>
--------------------------------------------

in backcolor.asp the code that uses the color from bgselector.asp is
<%
Dim strBackColor
strBackColor = Request.Form("backcolor")
%>

How do I implement this? Here is what I tried that did not work to change
the backcolor of backcolor.asp

<html>
<head>
<title>backcolor</title>
<%
Dim strBackColor
strBackColor = Request.Form("backcolor")
%>
</head>
<body bgcolor=<%strBackcolor%>>

</body>
</html>

Any suggestions appreciated.
Thanks,
Rich
 
R

Rich

I figured this out:

<html>
<head>
<title>backcolor</title>
<%
Dim strBackColor
strBackColor = Request.Form("backcolor")
%>
</head>
<body bgcolor=<% response.write strBackColor%>>

</body>
</html

I forgot about <%response.write strBackColor%>
 
E

Evertjan.

=?Utf-8?B?UmljaA==?= wrote on 23 mrt 2006 in
microsoft.public.inetserver.asp.general:
 
M

Mike Brind

Or even:

<html>
<head>
<title>backcolor</title>
</head>
<body bgcolor=<% =Request.Form("backcolor")%>>
 
E

Evertjan.

ravichoudhari wrote on 24 mrt 2006 in
microsoft.public.inetserver.asp.general:
even <body bgcolor=<%=strBackColor%>> works.

Certainly, but to keep you straight for other insertions, that could have
spaces in the string, I suggest you always clientside quote the string:

<body bgcolor='<%=strBackColor%>'>

=========

btw, better use css styles:

<body style='background-color:<%=strBackColor%>;'>

or even more versatile:

<style>
body {background-color:<% = request.form("BackColor") %>;
color:<% = request.form("TextColor") %>;font-weight:600;}
</style>
</head>
<body>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top