SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
Thread: An asp code question
-
Oct 22, 2001, 16:32 #1
- Join Date
- Jul 2001
- Posts
- 48
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
An asp code question
This is what i just made up to ask this question (there may be errors, but you will get the point):
----------------------------------------------------
<%
cpu1fromdatabase = "1GHz"
cpu1price = 100
cpu2fromdatabase = "2GHz"
cpu2price = 200
cpu3fromdatabase = "3GHz"
cpu3price = 300
%>
<html>
<head>
<title>thispage.asp</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<% select = Request.Form("select") %>
<form name="form1" method="post" action="thispage.asp">
CPU:
<select name="select">
<option value="<%=cpu1price%>"><%=cpu1fromdatabase%> [+ $<%=cpu1price-select%>]</option>
<option value="<%=cpu2price%>"><%=cpu1fromdatabase%> [+ $<%=cpu1price-select%>]</option>
<option value="<%=cpu3price%>"><%=cpu1fromdatabase%> [+ $<%=cpu1price-select%>]</option>
</select>
<br>
<br>
<input type="submit" name="Recalc" value="Recalculate">
</form>
</body>
</html>
-----------------------------------------------------
As you can see, it gets the values from the database, then creates the form by using the name and added charge. the value is the price so that when on is selected, the select variable will be valued accordingly. WHat i need this to do is to start off with select being the currently selected choice, then when recalculate is pressed, it reloads the page, but the select variable is now what was selected. This is the base for a pc config script.
Thanks
-
Oct 22, 2001, 19:00 #2
Basically what you need to do is this:
Code:<% Response.Write "<option " If select = cpu1price Then Response.Write "selected " End if Response.Write "value=""" & cpu1price & """>" & cpu1fromdatabase & " [+ $" & cpu1price-select & "]</option>" Response.Write "<option " If select = cpu1price Then Response.Write "selected " End if Response.Write "value=""" & cpu2price & """>" & cpu1fromdatabase & " [+ $" & cpu1price-select & "]</option>" Response.Write "<option " If select = cpu1price Then Response.Write "selected " End if Response.Write "value=""" & cpu3price & """>" & cpu1fromdatabase & " [+ $" & cpu1price-select & "]</option>" %>
http://www.echo-consulting.net - Sound Solutions for Online Inspriations.
-
Oct 23, 2001, 03:47 #3
- Join Date
- Jul 2001
- Location
- Scotland
- Posts
- 4,836
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Ok, you can't use select, becuse it is a function in VBScript, so I've fixed the code;
Code:Response.Write("<option ") If formSelect = cpu1price Then Response.Write("selected ") Response.Write("value=""" & cpu1price & """>" & cpu1fromdatabase & " [+ $" & cpu1price & "]</option>" ) Response.Write("<option ") If formSelect = cpu2price Then Response.Write("selected ") Response.Write("value=""" & cpu2price & """>" & cpu2fromdatabase & " [+ $" & cpu2price & "]</option>" ) Response.Write("<option ") If formSelect = cpu3price Then Response.Write("selected ") Response.Write("value=""" & cpu3price & """>" & cpu3fromdatabase & " [+ $" & cpu3price & "]</option>" )
-
Oct 23, 2001, 13:37 #4
- Join Date
- Jul 2001
- Posts
- 48
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
thanks to both of you for the help. I got it figured out now. And about that variable, that isnt waht i was going to make it, i just made tat script real fast to use as an example.
-
Oct 23, 2001, 23:06 #5
good catch dhtmlgod. I can't tell you how much time I have wasted on reserved names.
http://www.echo-consulting.net - Sound Solutions for Online Inspriations.
Bookmarks