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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automaticaly insert multiple dropdown list

Status
Not open for further replies.

Bramvg

IS-IT--Management
Jan 16, 2001
135
BE
Hi,

In my application [testing tool] I want to display dynamically multiple dropdown items in a question.

I explain:
The question itself is stored in the database like:
&quot;On the picture above you see the <tag> which was built in the year <tag>.&quot;

In another table of my database I store the information which will replace the '<tag>' sign, because I can easyly do a &quot;REReplace&quot;. Now, it works fine for e.g. a text input field. But I want more ;-)

Saying: I want to replace the first &quot;<tag>&quot; he finds with info stored in my table T_MultipleDropdown. The table looks like:

First record:
--------------------
QuestionID = 44
Place = 1 [indiciates the place of the <tag> in the question]
Value1 = Porsche
Value2 = Mustang
Value3= Chevrolet

Second record:
--------------------

QuestionID = 44
Place = 2 [indiciates the place of the <tag> in the question]
Value1 = 1971
Value2 = 1974
Value3= 1975


Now, the result should be:
&quot;On the picture above you see the Porsche/Mustang/Chevrolet which was built in the year 1971/1974/1975.&quot;

Where the options should be like:
<select name dropdown=1><option value=1>Porsche<option value=2>Mustang<option value=3>Chevrolet</select>

<select name dropdown=2><option value=1>1971<option value=2>1974<option value=3>1975</select>


I manage to replace the &quot;<tag>&quot; signs with this code:
#REReplace(&quot;#Question#&quot;,&quot;<tag>&quot;,&quot;<select name=optie><option>1<option>2</select>&quot;,&quot;ALL&quot;)#

The result is that i only get to see:

OR: all the same content in each 'dropdowner'
OR: The question repeats itself 3 times...


I hope this was/is clear and someone can help me out on this.

With kind regards
Bram







 
Hey Bram,

I think this may do what you want.

<cfquery name=&quot;q1&quot; ...
select * from tableName where questionID=44
order by place asc
</cfquery>

<cfloop query=&quot;q1&quot;>
<cfset &quot;var#currentRow#&quot;=&quot;<select name=&quot;dropdown2&quot;><option value=1>#q1.value1#<option value=2>#q1.value2#<option value=3>#q1.value3#</select>&quot;>
</cfloop>

<cfset x=1>
<cfloop
condition=&quot;findnocase(&quot;<tag>&quot;,question) gt 0 and isdefined(&quot;var#x#&quot;)&quot;
>
<cfset question=replace(question,&quot;<tag>&quot;,evaluate(&quot;var#x#&quot;))>
<cfset x=x+1>
</cfloop>

Let me know if you have any problems as I can't really test it.
GJ
 
Hi Gunjack!

Once again many thanks for the help.

The code you sent me is working, but not completely how it should ;-(

I explain: indeed the '<tag>' sign is replaced, but it's only replaced the first time in the sentence, with the last dropdown list!

So, the result is:
&quot;On the picture above you see the 1971/1974/1975 which was built in the year.&quot;


The second (and/or third) dropdown is not replaced + the replacement of the first dropdown list is not correct.

It seems that the variable you defined 'question' [<cfset question=replace(question,&quot;<tag>&quot;,evaluate(&quot;var#x#&quot;))>]
is overwriting itself while going through the loop.

Any ideas on how to resolve this?

Many thanks in advance!
Bram

ps: I'm always very impressed by your posts on this forum, you seems to be 'pretty good', which is an understatement.
Do you have a website?


 
Hey Bram,

I went ahead and set this up so I could test it and found a few syntax errors that kept it from compiling and then from showing the drop downs correctly. I don't know if you found/fixed these or if they might be causing part of the problem. Here's my revised code:

<cfloop query=&quot;q1&quot;>
<cfset &quot;var#currentRow#&quot;=&quot;<select name=&quot;&quot;dropdown2&quot;&quot;><option value=1>#q1.value1#<option value=2>#q1.value2#<option value=3>#q1.value3#</select>&quot;>
</cfloop>

<cfset x=1>
<cfloop condition=&quot;findnocase(&quot;&quot;<tag>&quot;&quot;,question) gt 0 and isdefined(&quot;&quot;var#x#&quot;&quot;)&quot; >
<cfset question=replace(question,&quot;<tag>&quot;,evaluate(&quot;var#x#&quot;))>
<cfset x=x+1>
</cfloop>

Once I fixed the syntax errors, it ran and worked correctly with a test &quot;question&quot; variable. If it still gives you the errors, can you post your code starting with the query &quot;q1&quot; on through the last <cfloop>? My code is obviously not identical to yours in my test scenario so if yours doesn't work, I'll need to look at the differences to see where the problem might be.

Thanks for the kind words :) I own and run a CF hosting/design company and our website is although I have to say it's really outdated. I never seem to have time to put into it with everything else goin on ;) A few CF sites I've done are and The majority of my CF coding these days is behind the scenes work that runs the business.

Take care and let me know if you still have trouble,
GJ
 
Hi Gunjack,


Indeedo, I changed some of the code because there were some minor syntax 'errors' but still, no luck ;-)

If I do an output within in the cfloop I get to see:

&quot;On the picture above you see the Porsche/Mustang/Chevrolet which was built in the year. On the picture above you see the which was built in the year 1971/1974/1975 .&quot;

Instead of: &quot;On the picture above you see the Porsche/Mustang/Chevrolet which was built in the year 1971/1974/1975 .&quot;


When I do an output outside the cfloop of 'question' I see:

&quot;On the picture above you see the Porsche/Mustang/Chevrolet which was built in the year.&quot;


The syntax works fine of the replacement, but not all options are visible. Well, they are but the sentence is repeated twice!?


If you need more information, or the script itself, just mail me and I send it over, I'm realy stuck with it!

Again, many thanks!
Bram

btw: you can also mail me at: bram@vangrimbergen.com
 
Hey Bram,

I just thought of one thing that may be the problem. When I tested it locally, I created a local variable to contain static text to search and replace on. Since you are getting this text from a database, your initial question variable will be a query variable. I don't recall ever trying to modify a query variable so I don't know if it will give an error or mixed results. If you are passing the query variable straight in to the replacement code, try using a local variable instead like this:

<cfset question=q1.QuestionText>

If this is what you're already doing, just let me know and I'll contact you to get your specific code.

GJ
 
Hi GJ,

That is indeed what I'm doing ;-)
But doesn't work...

Thanks for helping me out and putting time into this!

With kind regards
Bram


 
Hey Bram,

It appears to be what I described in my last post or I should say almost what I described. Each time through the second loop, you're setting #question# to &quot;replace(query.Variable,&quot;<tag>&quot;,evaluate(&quot;var#x#&quot;))&quot;. This takes the query variable and replaces &quot;<tag>&quot; with the current variable &quot;var#x#&quot;. Since #query.Variable# never changes, each time through the loop you are starting over with the original value of #query.Variable# and replacing the first occurance of &quot;<tag>&quot; with the current value of &quot;var#x#&quot;.

If you put this line before the second loop, I think it should work for you.

<cfset question=query.Variable>

Let me know if you still have any problems.
GJ
 
Oops,

I forgot to mention that you also need to replace the two occurances of &quot;query.Variable&quot; in the second <cfloop> section with the &quot;question&quot; variable.

<cfloop condition=&quot;#findnocase(&quot;<tag>&quot;,question)# gt 0 and#isdefined(&quot;var#x#&quot;)#&quot;>
<cfset question=replace(question,&quot;<tag>&quot;,evaluate(&quot;var#x#&quot;))>

Good luck,
GJ
 
Hi GJ,


That DID THE TRICK! Thank you very much for the time you invested into this !!!!!

With best regards
bram
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top