Forums

This topic is locked

Dropdown populated from datafile

Posted 08 Jul 2003 07:21:13
1
has voted
08 Jul 2003 07:21:13 Roger Smithe posted:
I would like to know how to get values from two fields in a datafile that populated the dropdown menu.

e.g. tblPositionList has two fields Position and PositionCode. Position is used to populate the dropdown. When a user selects the Position I want to input it and the PositionCode into a third table.

Getting Position or PositionCode into the other table works fine but nothing I've tried has gotten both into the other table.

Any Ideas Would Be Appreciated

Replies

Replied 10 Jul 2003 14:14:43
10 Jul 2003 14:14:43 Jim Rol replied:
What do you use those for?
Position and PositionCode are they the labels and values of the dropdown?
And do you want to insert them both into a database table?

Please some more information or at least better explained.
Thanks
Jim

Edited by - on 10 Jul 2003 14:15:29
Replied 11 Jul 2003 06:38:20
11 Jul 2003 06:38:20 Roger Smithe replied:
Jim
This is a form using, among other things, a dropdown menu.

Position and PositionCode are field values in a table populating the dropdown menu.

When the user selects the Position (field1) from the dropdown I also want to get the PositionCode (field2)

I want to be able to store both these values in the recordset defined for the form.
Replied 11 Jul 2003 09:28:56
11 Jul 2003 09:28:56 Jim Rol replied:
Just store both the the values you want in the other table as the value for the dropdown.
DW only has the option to store one recordsetitem in it so you'll have to do it manually.
Click the dropdown in designview and switch to code view. Find the option tag and enter the other recordset field with it:
So first you have:
<pre id=code><font face=courier size=2 id=code>&lt;option value="&lt;%=(rsYourRS.Fields.Item("Position".Value)%&gt;"&gt;&lt;%=(rsYourRS.Fields.Item("Position".Value)%&gt;&lt;/option&gt;</font id=code></pre id=code>

And change this to:

<pre id=code><font face=courier size=2 id=code>&lt;option value="&lt;%=(rsYourRS.Fields.Item("Position".Value)<font color=red> & " " & (rsYourRS.Fields.Item("PositionCode".Value)</font id=red>%&gt;"&gt;&lt;%=(rsYourRS.Fields.Item("Position".Value)%&gt;&lt;/option&gt; </font id=code></pre id=code>

Hope this helps

Edited by - on 11 Jul 2003 09:31:08
Replied 11 Jul 2003 23:03:09
11 Jul 2003 23:03:09 Roger Smithe replied:
Jim
Thanks for your help.
I've implemented a modified version of you solution.

&lt; option value="&lt; % = (rsLookupPosition.Fields.Item("positioncode".Value) & "," & (rsLookupPosition.Fields.Item("position".Value) %&gt;"&gt;&lt;% = (rsLookupPosition.Fields.Item("position".Value)% &gt;&lt; /option &gt;

This gives me a separator between the data which currently gets inserted in the 'Position' field e.g. 'Check Pilot,53'
It isn't what I'm looking for however.

I'm a FoxPro/PowerBuilder programmer so I thought it would be easy to do a substr() and At() funtions to divide it into 'Check Pilot' for the Position and '53' for the PositionCode. Not So.

One possible solution spoke about dividing and storing in arrays! Seems a bit much.

Couldn't I just define two variables and store the parts into them and then edit the INSERT SQL statement to include the two new variables?

What would be your solution?

Appreciate your help
Replied 11 Jul 2003 23:50:27
11 Jul 2003 23:50:27 Jim Rol replied:
I think i didn't understand what you were trying to achief because i thought you wanted to combine the two values and insert them into one field in your database...

If i read it correctly what you are trying to explain here is that you want to seperate them and store both values into differend fields.

This can best be done as you started. Use the comma as seperator like your example. Then use the split function to store both values into different variables and edit the insert sql wich stores them into the database.
Here is the split function:
<pre id=code><font face=courier size=2 id=code>
bothValues= request("nameOfYourDropdown"
vars = split(bothValues,","
var1 = vars(0)
var2 = vars(1)
</font id=code></pre id=code>

So the split function stores the values into an array. (Array items start at 0), so the first item in the array vars (var1) is your positioncode and the second item (var2) is the position.

Now all you have to do is edit the insert SQL.

Let me know if this helped.
Jim
Replied 12 Jul 2003 21:06:48
12 Jul 2003 21:06:48 Roger Smithe replied:
Jim
Thanks for your help...again

I get the data split ok but I am having trouble getting the values into the data fields. No matter what I try I get var2 inserted into PositionCode and var1 into Position. I'm apparently am missing how to insert the variable instead of the variable name. What am I missing??

Below is a link to the asp code as a text file showing how I've implemented the solution (incorrectly).
68.84.197.216/two_Fields.txt

I can email the datafile and the actual page if it would help.
Replied 13 Jul 2003 11:36:14
13 Jul 2003 11:36:14 Jim Rol replied:
Hello alpha1138,

first:
The dropdown on your site only contains 1 value. You have to populate it with your two values Position and positioncode seperated by a comma like you posted.
Second:
The split function is not a javascript function that splits the value before the data is submitted, but a asp function that gets the value of your dropdown after the form is submitted (so the second time the page loads) and divides the value in two variables wich the insert sql needs to store them into the database. So this has to take place before the insert actualy takes place (top of the page).
I have made an example. You can see it in action here www.hoornaaronline.nl/test/pag_01.asp
And this is the code:
<pre id=code><font face=courier size=2 id=code>
&lt;%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%&gt;
&lt;%
'check to see if from was submitted, and if so get the values from the dropdown
if request("send"&lt;&gt;"" then
Dim data, vars, var1, var2, submitted
data = request("PostedPosition"
vars = split(data,","
var1 = vars(0)
var2 = vars(1)
submitted = true 'we have values to display so we can show it on the page
end if
%&gt;

&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Example plitting values submitted&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;style type="text/css"&gt;
&lt;!--
body {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
}
--&gt;
&lt;/style&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;In this example i use static values wich you have te replace by the dynamic
ones from your recordset:&lt;br&gt;
&lt;em&gt;&lt;font color="#990000"&gt;&lt;option value=&quot;examplePosition 1 value 1,examplePosition 1 value 2&quot;&gt;Position
1&lt;/option&gt;&lt;/font&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Replace this by:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;font color="#990000"&gt;&lt;option value=&quot;&lt; % = (rsLookupPosition.Fields.Item(&quot;positioncode&quot<img src=../images/dmxzone/forum/icon_smile_wink.gif border=0 align=middle>.Value) &amp; &quot;,&quot; &amp; (rsLookupPosition.Fields.Item(&quot;position&quot<img src=../images/dmxzone/forum/icon_smile_wink.gif border=0 align=middle>.Value)
%&gt;&quot;&gt;&lt;% = (rsLookupPosition.Fields.Item(&quot;position&quot<img src=../images/dmxzone/forum/icon_smile_wink.gif border=0 align=middle>.Value)% &gt;&lt; /option&gt; &lt;/font&gt;&lt;/em&gt;&lt;/p&gt;
&lt;form name="form1" method="post" action="pag_01.asp"&gt;
&lt;select name="PostedPosition" id="PostedPosition"&gt;
&lt;option value="examplePosition 1 value 1,examplePosition 1 value 2"&gt;Position 1&lt;/option&gt;
&lt;option value="examplePosition 2 value 1,examplePosition 2 value 2"&gt;Position 2&lt;/option&gt;
&lt;option value="examplePosition 3 value 1,examplePosition 3 value 2"&gt;Position 3&lt;/option&gt;
&lt;/select&gt;
&lt;input type="submit" name="Submit" value="Submit"&gt;
&lt;input name="send" type="hidden" id="send" value="1"&gt;
&lt;/form&gt;

&lt;%
if (submitted) then 'This doesn't display the first time you load the page because we don,t have any values to show
response.write "The value of the dropdown before the "","": Var1 = " & var1 & "&lt;br&gt;"
response.write "The value of the dropdown after the "","": Var2 = " & var2 & "&lt;br&gt;"
end if
%&gt;
&lt;/body&gt;
&lt;/html&gt;
</font id=code></pre id=code>


The code Dreamweaver uses to insert the values is set up to be very dynamicaly and very hard to adjust. I think it is easier to hard code your sql insert.

Jim
Replied 13 Jul 2003 11:41:23
13 Jul 2003 11:41:23 Jim Rol replied:
Somehow this forum replaeced some code with smilies
Here you can finde the code

www.hoornaaronline.nl/test/code.txt

Jim
Replied 15 Jul 2003 17:42:09
15 Jul 2003 17:42:09 Roger Smithe replied:
Thanks for your help Jim.
I'll try and get this implemented.
Replied 16 Jul 2003 08:13:11
16 Jul 2003 08:13:11 Jim Rol replied:
That was a rather short reply...
Did you understand it?
I hope you can work it out. Let me kown.

Good luck
Replied 21 Jul 2003 08:24:39
21 Jul 2003 08:24:39 Roger Smithe replied:
Jim,
Sorry about the delay. Yes I did manage to get it implemented and as you said it was neccessary to write my own SQL INSERT to store the form values.

I never could figure out how to modify the insert code DWMX created.

Thanks again.

I'm going to post the code and table structures in a new topic so other may benefit.

Reply to this topic