| | |
Make an option stay selected
Please support our ASP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Feb 2008
Posts: 174
Reputation:
Solved Threads: 3
I thought this was a simple task to do, but not.
I just want the option stay selected when a value from the session variable exists, AND it does after the form has been submitted. So why can't the option value stay selected as long as session is populated.
If I put a static value in the loop like this:
If RegID = 5 Then ...
Then the option stays selected at this post.
I just want the option stay selected when a value from the session variable exists, AND it does after the form has been submitted. So why can't the option value stay selected as long as session is populated.
If I put a static value in the loop like this:
If RegID = 5 Then ...
Then the option stays selected at this post.
ASP Syntax (Toggle Plain Text)
SQL = "SELECT * FROM tbregion ORDER BY region ASC" Set RS = Server.CreateObject("ADODB.recordset") RS.Open SQL,Conn Session("region") = Request.Form("regv") region = Session("region") %> <form name="region" action="select_menu.asp" method="post"> <select name="regv" onchange="region.submit()"> <option value="">Make a selection</option> <option value="">------------------</option> <% RegID = RS("regionID") x=0 Do While Not RS.EOF If RegID = region Then For i = 1 To Region Response.Write("<option value='" & RS("regionID") & "' SELECTED>" & RS("region") & "</option>") x=x+1 Next Else x=x -1 For i = 1 To RegID Response.Write("<option value='" & RS("regionID") & "'>" & RS("region") & "</option>") Next End If RS.MoveNext Loop RS.Close Set RS = Nothing %> </select> </form> <% Response.Write("<a href='category.asp?clevel=1®v="& region & "'>Link</a>") %>
Last edited by TobbeK; Feb 22nd, 2008 at 8:00 am.
•
•
Join Date: May 2005
Posts: 514
Reputation:
Solved Threads: 19
Have you tried declaring these?
I have ran into some odd ball issues when comparing text field to integer.
Try setting both as integer then do your compare.
I have ran into some odd ball issues when comparing text field to integer.
Try setting both as integer then do your compare.
•
•
Join Date: Feb 2008
Posts: 174
Reputation:
Solved Threads: 3
Now it works, with a small little bug.
If I have selected an option with (let's say value=20) then responded value is 19. So there is a miscalculation that takes the actual value and set it to -1.
I don't know where the bug is.
It is possible to set the session variable to +1 but I really like know where the error is.
If I have selected an option with (let's say value=20) then responded value is 19. So there is a miscalculation that takes the actual value and set it to -1.
I don't know where the bug is.
It is possible to set the session variable to +1 but I really like know where the error is.
ASP Syntax (Toggle Plain Text)
SQL = "SELECT * FROM tbregion ORDER BY region ASC" Set RS = Server.CreateObject("ADODB.recordset") RS.Open SQL,Conn Dim region %> <form name="region" action="select_menu.asp" method="post"> <select name="regv" onchange="region.submit()"> <option value="">Make a selection</option> <option value="">------------------</option> <% Session("region") = Request.Form("regv") region = Session("region") regionID = RS("regionID") If region <> "" Then If region <> "0" Then Do Until Clng(regionID) = Clng(region) Response.Write("<option value=""" & regionID & """SELECTED>" & RS("region") & "</option>") regionID = regionID + 1 RS.MoveNext Loop Do Until RS.EOF Response.Write("<option value=""" & regionID & """>" & RS("region") & "</option>") regionID = regionID + 1 RS.MoveNext Loop End If End If If region = "" OR region = "0" Then Do Until RS.EOF Response.Write("<option value=""" & regionID & """>" & RS("region") & "</option>") regionID = regionID + 1 RS.MoveNext Loop End If %> </select> </form> <% Response.Write("<a href='category.asp?clevel=1®v="& region & "'>Link</a>") %>
Last edited by TobbeK; Feb 22nd, 2008 at 10:09 am.
•
•
Join Date: Sep 2007
Posts: 1,080
Reputation:
Solved Threads: 68
You're setting RegID out of the Do While Not RS.EOF, so therefore it is never being set, or it is being set to the first record only.
Move it down to within the do while not rs.eof.
Move it down to within the do while not rs.eof.
SQL = "SELECT * FROM tbregion ORDER BY region ASC"
Set RS = Server.CreateObject("ADODB.recordset")
RS.Open SQL,Conn
Session("region") = Request.Form("regv")
region = Session("region")
%>
<form name="region" action="select_menu.asp" method="post">
<select name="regv" onchange="region.submit()">
<option value="">Make a selection</option>
<option value="">------------------</option>
<%
RegID = RS("regionID")
x=0
Do While Not RS.EOF
If RegID = region Then
For i = 1 To Region
Response.Write("<option value='" & RS("regionID") & "' SELECTED>" & RS("region") & "</option>")
x=x+1
Next
Else
x=x -1
For i = 1 To RegID
Response.Write("<option value='" & RS("regionID") & "'>" & RS("region") & "</option>")
Next
End If
RS.MoveNext
Loop
RS.Close
Set RS = Nothing
%>
</select>
</form>
<%
Response.Write("<a href='category.asp?clevel=1®v="& region & "'>Link</a>")
%>•
•
Join Date: Feb 2008
Posts: 174
Reputation:
Solved Threads: 3
Great as usual, THANKS!
Here's a new question within (ok maybe a little outside the scope of the thread).
The sending form is suppuse to send a value back to itself, that means same page. Now, I need to use the exact URL of the page so that value landing at the same spot again. I have tried to put variables in the form action but doesn't help much.
Example:
http://www.webpage.com?category.asp?id=1&anotherid=2
When sending the form value, the only thing happens is that the form value appends to the URL like this:
http://www.webpage.com?category.asp?regv=5
So I'm not at the same place as before.
Any ideas are extremely welcome
Here's a new question within (ok maybe a little outside the scope of the thread).
The sending form is suppuse to send a value back to itself, that means same page. Now, I need to use the exact URL of the page so that value landing at the same spot again. I have tried to put variables in the form action but doesn't help much.
Example:
http://www.webpage.com?category.asp?id=1&anotherid=2
When sending the form value, the only thing happens is that the form value appends to the URL like this:
http://www.webpage.com?category.asp?regv=5
So I'm not at the same place as before.
Any ideas are extremely welcome
•
•
Join Date: Feb 2008
Posts: 174
Reputation:
Solved Threads: 3
OK, It is my swenglish
Let's say i have clicked on a link and landed at this page with this URL and values
Example: category.asp?id=2&otherid=3
Now, this is a page with specific content set by the appended values:
I wan't to send a value from the dropdown form at that page, and land again at exact page content.
What's happends now is that I land at category.asp?regv=5 (the regv=5 is the form value) and the other appended values is lost
This is the form settings:
<form name="region" action="category.asp" method="get">
<select name="regv" onchange="region.submit()">
I have tried use post also:
<form name="region" action="category.asp" method="post">
<select name="regv" onchange="region.submit()">
After sending the form value I like land at the exact URL again
For example: category.asp?id=2&otherid=3
I have tried to change the form action to append variables but no luck. It only sends the form value
Let's say i have clicked on a link and landed at this page with this URL and values
Example: category.asp?id=2&otherid=3
Now, this is a page with specific content set by the appended values:
I wan't to send a value from the dropdown form at that page, and land again at exact page content.
What's happends now is that I land at category.asp?regv=5 (the regv=5 is the form value) and the other appended values is lost
This is the form settings:
<form name="region" action="category.asp" method="get">
<select name="regv" onchange="region.submit()">
I have tried use post also:
<form name="region" action="category.asp" method="post">
<select name="regv" onchange="region.submit()">
After sending the form value I like land at the exact URL again
For example: category.asp?id=2&otherid=3
I have tried to change the form action to append variables but no luck. It only sends the form value
Last edited by TobbeK; Feb 22nd, 2008 at 12:59 pm.
•
•
Join Date: Sep 2007
Posts: 1,080
Reputation:
Solved Threads: 68
Put the form as POST, otherwise your querystring will be overridden. Then for your form action put :
ASP Syntax (Toggle Plain Text)
action="<%= Request.ServerVariables("SCRIPT_NAME") & "?" & Request.ServerVariables("QUERY_STRING") %>"
![]() |
Similar Threads
- Tutorial: Understanding ASP classes (ASP)
- dropdownlist value doesnt get selected (ASP)
- Open In New Window Php (PHP)
- How do I delete an instance of an Array? (C++)
- Trouble getting code to compile (C++)
Other Threads in the ASP Forum
- Previous Thread: IIS Problem ?
- Next Thread: Image does not view
| Thread Tools | Search this Thread |
archive asp asp.net aspandmssqlserver2005 aspandmssqlserver2005connection aspconnection calendar changeable connection current database databaseconnection diagnostics dreamweaver excel fso html iis microsoft msmsql mssql2005 mssqlserver2005 mssqlserver2005andasp mssqlserverandasp opentextfile record searchbox selectoption server single specfic sqlserver sqlserverconnection toolkit web webserver windows7






