Generating a dynamic questionaire
A developer recently asked me how to generate dynamic questions. Dynamic as in: there is a general topic and then details. E.g.
| Please state the number of building blocks per shape | |||
|---|---|---|---|
| Shape | Red | Blue | Yellow |
| Triangle | 5 | 6 | 4 |
| [Button: add row] | |||
tmpCount := @Elements(qdimensions)+1;
tmpNum := "0":"1":"2":"3":"4":"5":"6":"7":"8":"9";
colCount := @Subset((tmpNum*+tmpNum);tmpCount);
tmpStart := "<table id=\"qtable"+qnumber+"\"> <tr> <th colspan=\""+tmpCount+"\" >"+question+"</th> </tr><tr>";
tmpHeader := "<th>"+qdimensions+"</th>"<;br /> tmpLineStart := "</tr><tr> <td><input type=\'text\' id=\"row1col1\" /> </td>"
tmpQuestions := "<td><input type=\"text"\ dojotype=\""+qType+"\" title=\""+qdimentions+"\" id=\"row1col"+colCount+" /> </td>";
tmpLineEnd := "</tr>"
tmpEnd := "<tr> <th colspan=\""+tmpCount+"\" ><input type=\"button\" value=\"Add Row\" onClick=\"addRow('qtable"+qnumber+"')\" / ></th> </tr>"
@Implode(tmpStart:tmpHeader:tmpLineStart:tmpQuestions:tmpLineEnd:tmpEnd;@NewLine)
The code is a rough outline, so cut and paste might not work and you also might need to work on the ids for the input fields. But you get the idea. The trick here: the multi-value field qDimensions creates as many th/td/input as we actually need. The questionnaire form would have an embedded view showing that hidden field as passthru html, so you get all questions rendered. A JavaScript function addRow(id) takes the ID of the table as parameter, so you know what table to use. Last stop: make the questions submit to an agent, so you can process all the fields.




Comments
I'd be interested too. Could you pass on your email address?
Posted by KamauDK At 18:09:00 On 05/13/2009 | - Website - |
I have a fully function web survey system that I developed for the company and which we use regularly. If you want a copy, email me.
Regards
Posted by Tim Crannigan At 21:19:08 On 02/12/2009 | - Website - |