Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Page reproduction problem 1

Status
Not open for further replies.

unicorn11

Programmer
Jun 10, 2000
392
0
0
IN
Hi everybody<br>&nbsp;The problem i am having is that there is a user registeration page that has a country field with about 100 options in a select field in the form <br>&nbsp;<br>&nbsp;I have to create a if update profile page that i now need to show that country as selected <br>&nbsp;<br>&nbsp;What would be the most simplest method to do this <br>&nbsp;the sample code of the select button is <br>&nbsp;<br><FONT FACE=monospace> &lt;select name= country&gt;<br>&nbsp;&nbsp;&lt;option value=&quot;IN&quot;&gt;India&lt;/option&gt;<br>&nbsp;&nbsp;&lt;option value=&quot;XX&quot;&gt;XXXX&lt;/option&gt;<br>&nbsp;&nbsp;&lt;option value=&quot;YY&quot;&gt;YYY&lt;/option&gt;<br>&nbsp;&lt;/select&gt;</font><br><br>Thank's for any time spent on the problem <br>&nbsp; <p>Unicorn11<br><a href=mailto:webmaster@tripmedia.com>webmaster@tripmedia.com</a><br><a href= > </a><br>Hi there it all likeminded fellows!!!!!!
 
Hi,<br><br>Suppose you read the information entered like this<br><br>countrychoose = Request.Form(&quot;country&quot;)<br><br>In order for you retrieve and redisplay the information entered you do this<br><br>&lt;select name= country&gt;<br>&nbsp;&nbsp;&lt;option selected&gt;&lt;%=countrychoose%&gt;&lt;/option&gt;<br>&nbsp;&nbsp;&lt;option value=&quot;IN&quot;&gt;India&lt;/option&gt;<br>&nbsp;&nbsp;&lt;option value=&quot;XX&quot;&gt;XXXX&lt;/option&gt;<br>&nbsp;&nbsp;&lt;option value=&quot;YY&quot;&gt;YYY&lt;/option&gt;<br>&nbsp;&lt;/select&gt;<br><br>good luck<br><br><br><br><br> <p>din<br><a href=mailto:tidrus@bigfoot.com>tidrus@bigfoot.com</a><br><a href= > </a><br>ICQ # 26094048
 
See the country in the database in YY the value that is set <br>&nbsp;I also want it toi select the country name <br>&nbsp;<br>&nbsp;But a if condition is not the solution i do want to that check for the country and put is dynamically<br><br>&nbsp; <p>Unicorn11<br><a href=mailto:webmaster@tripmedia.com>webmaster@tripmedia.com</a><br><a href= > </a><br>Hi there it all likeminded fellows!!!!!!
 
Here, I just wrote this procedure to create your select list box.&nbsp;&nbsp;I think it will do what you want it to.<br><br>Heres how you use it:<br><br>&lt;%<br><font color=#009900> 'Get the country from the database field<br>'(assumes you've already opened the recordset that identifies the user)</font><br>Dim sCountry<br>sCountry = Rs.Fields(&quot;country&quot;).value<br><br><font color=#009900> 'create an sql statement that will generate a RS of all countries.&nbsp;&nbsp;we will pass this to the procedure</font><br>Dim sCountriesSQL<br>sCountriesSQL = &quot;SELECT country FROM MyTableOfCountries ORDER BY country&quot;<br><br><font color=#009900> <br>'identify your datasource... you've probably already done this when you got the users preferences but anyway...</font><br>Dim DSN <br>DSN = &quot;Driver={SQL Server};Server=(local);Database=MyDB;uid=sa;pwd=;&quot;<br>%&gt;<br><br><font color=#009900><br>Now draw the select list and use the routine to build the option list!</font><br>&lt;SELECT name=country&gt;<br>&lt;% WriteOptionList sCountriesSQL, DSN, sCountry %&gt;<br>&lt;/SELECT&gt;<br><br><br>&lt;%<br><font color=#009900> <br>'INPUT: sql statement, datasource, the string that may be selected<br>'OUTPUT: an option list<br>'please note, it will check the first field returned from your sql statment for the value.&nbsp;&nbsp;you can easily modify this if you have to if for example your sql statement is &quot;Select countryId, CountryName from ...&quot;<br></font><br><br>Sub WriteOptionList (sql, dsn, selected)<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Dim Rs, item<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set Rs = Server.Createobject(&quot;ADODB.Recordset&quot;)<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Rs.Open sql, dsn<br> <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Do While Not Rs.EOF<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;item = Trim(Rs.Fields(0).Value)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Response.Write &quot;&lt;option&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If item = selected Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Response.Write &quot; SELECTED&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End If <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Response.Write &quot; value='&quot; & item & &quot;'&gt;&quot; & item & &quot;&lt;/option&gt;&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Rs.Movenext<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Loop<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Rs.close<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set Rs = nothing<br><br>End Sub<br><br>%&gt;<br><br><br>Happy programming!
 
It's also possible to have a 2d array with the values for the country and its code. This is the same logic approach as Mr. jfriestman's example above but using an array as opposed to a recordset. I do this with an application level array:<br><br>in global.asa file:<br>---------------------------------<br>dim countries(249,1)<br>countries(0,0) = &quot;001&quot;<br>countries(0,1) = &quot;United States&quot;<br>countries(1,0) = &quot;002&quot;<br>countries(1,1) = &quot;Afghanistan&quot;<br>countries(2,0) = &quot;003&quot;<br>countries(2,1) = &quot;Albania&quot;<br>...<br>countries(247,0) = &quot;248&quot;<br>countries(247,1) = &quot;Zaire&quot;<br>countries(248,0) = &quot;249&quot;<br>countries(248,1) = &quot;Zambia&quot;<br>countries(249,0) = &quot;250&quot;<br>countries(249,1) = &quot;Zimbabwe&quot; <br>Application(&quot;countries&quot;) = countries<br><br><br>In your asp file:<br>-------------------------<br>[Query to get user previous user selection USERCTY. Then:]<br>&lt;select name=&quot;billcountry&quot; size=&quot;1&quot;&gt;<br>&lt;option value=&quot;&quot; &gt;-------SELECT-------&lt;/option&gt;<br>&lt;% <br>&nbsp;&nbsp;&nbsp;&nbsp;countrieslen = Ubound(Application(&quot;countries&quot;),1) <br>&nbsp;&nbsp;&nbsp;&nbsp;for i = 0 to countrieslen <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;val = Application(&quot;countries&quot;)(i,0)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;country = Application(&quot;countries&quot;)(i,1)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if val = USERCTY then sel = &quot;selected&quot; else sel = &quot;&quot; end if <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;response.write(chr(13)&&quot;&lt;option value=&quot;&chr(34)&val&chr(34)&&quot; &quot;&sel&&quot;&gt;&quot;&country&&quot;&lt;/option&gt;&quot;) <br>&nbsp;&nbsp;&nbsp;&nbsp;next<br><br>%&gt;<br>&lt;/select&gt; <p>--Will Duty<br><a href=mailto:wduty@radicalfringe.com>wduty@radicalfringe.com</a><br><a href= > </a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top