SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Enthusiast
    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

  2. #2
    grasshoppa Snowbird122's Avatar
    Join Date
    Apr 2001
    Location
    Austin
    Posts
    353
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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>" 
    %>
    Replace your 3 option lines with this and I think it will work. There may be some mistakes, but basicallly, you just test the cpuprice variable and see if it is equal to select. If it is, you put the word selected inside the option tag.
    http://www.echo-consulting.net - Sound Solutions for Online Inspriations.

  3. #3
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    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>" )

  4. #4
    SitePoint Enthusiast
    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.

  5. #5
    grasshoppa Snowbird122's Avatar
    Join Date
    Apr 2001
    Location
    Austin
    Posts
    353
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

Posting Permissions

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