Dynamic <INPUT name=" "> attributes

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default Dynamic <INPUT name=" "> attributes

    Hello everyone.

    I seem to be in a rut on a local intranet web application im working on. I am
    developing a questionaire for a portion of the intranet site that deals with
    surveys. The trouble I am running into is when it comes to update the database
    I want to insert the submitted data into. Before I continue I try to explain
    how this form and submission process works.

    I have table in MSSQL that contains a list of questions each with a unique ID
    (questionID) and another table that contains the answers. So right now, I have
    two tables, one for the answers (tblAnswers) and one that contains the
    questions (tblQuestions). Each table has a "questionID" field, one Primary Key
    field (in tblQuestions) and one Foreign Key field (in tblAnswers).

    The database tables works just fine so I am pretty confident of the
    architecture of the two tables.
    Here is my problem:

    I am assiging the <FORM> attribute, "name=", a dynamic name. The dynamic name
    is the questionID from tblQuestions. So this looks something like this:


    <CFQUERY name="RetrieveQuestions" datasource="#application.ds#">
    select * from tblQuestions
    </cfquery>

    <CFFORM name="myQuestions" action="myQuestions_insert.cfm>
    <tr>
    <cfoutput query
    <td>#questionBody#<td>
    <td><INPUT NAME=#questionID# type="text">
    </CFFORM>


    So this forms works just fine, it retrieves the correct questions and displays
    them and submits correctly. Now the major hiccup occurs. When it reaches the
    action-form "myQuestions_insert.cfm" i am having trouble retrieving the
    dynamically created FORM.<name> data (i.e. the answer to the question).
    So, in other words, if the questionID is '256' , a form element with the
    name '256' would be created. So to retrieve this I would insert the following
    CFML.

    <cfoutput> #FORM.256# <cfoutput>

    It works fine if i hard code the value of the question, the thing is i have
    hundreds of questions in the table and what I am trying to do is retrieve is
    the <name> portion of #FORM.<name>#. the closest i got to resolving this
    issue is that i created a <cfset> variable and tried to store the data in that.
    Here's the code:

    <cfset answer = 'FORM.#quesionID#'>

    Unfortunately CF treats this as a string and thats is just fine, but if i
    include the variable in the my query to input the data, it inputs the created
    string into the table. So i would have an answer as "FORM.256" and not what
    #FORM.256# is. I would like to retrieve what #FORM.256# contains and then post
    the answer into the database table (tblAnswers).

    Does anyone have any idea on how to correctly implement this? i have been
    stuck on this for 2 days now and I dont think it should be this difficult to do
    something that seams simple.

    Thanks in advance and i'm looking forward to any ideas or solutions.:confused;

    MajikMerlin Guest

  2. Similar Questions and Discussions

    1. Setting "URL Behaviour" to "Dynamic" has no effect
      Greetings When I set the "URL Behaviour" of a web reference an entry is created in the "Web.config", but the value in the "Web Reference URL"...
    2. could not read block 84253 of relation "tablename": Input/outputerror
      Hi: No way to access "tablename". Can I do something to recover? Is this a hardware error? PostgreSQL 7.4.5 on i686-pc-linux-gnu, compiled by...
    3. Problem with fopen("php://input", "r")
      Hello there, I am having problem opening the in-built php stream php://input According to the manual this has been integrated into php since...
    4. custom checkboxlist, attributes.add("Value",1) does not work
      Hello. I'm trying to create a custom checkboxlist, that uses a datarow as input to populate them. This works just fine, except that I can't seem...
    5. "buddy api" folder attributes
      Hi there, Is it possible to set the attribute of a folder to hidden using Buddy api? The help mentions that you can set the attribute of a file to...
  3. #2

    Default Re: Dynamic <INPUT name=" "> attributes

    <!----- FORM PAGE ----->
    <form action="yourActionPage.cfm" method="post">
    <table border="1">
    <tr>
    <td><b>Row</b></td>
    <td><b>Quest. ID</b></td>
    <td><b>Answer</b></td>
    </tr>
    <cfoutput query="RetrieveQuestions">
    <tr>
    <td>#CurrentRow#</td>
    <td>#questionID#</td>
    <td><input type="text" name="answer#CurrentRow#">
    <input type="hidden" name="questionID#CurrentRow#" value="#questionID#">
    </td>
    </tr>

    </cfoutput>
    </table>
    <cfoutput>
    <input type="hidden" name="numberOfQuestions"
    value="#RetrieveQuestions.recordCount#">
    </cfoutput>
    <input type="submit">
    </form>


    <!-------- ACTION PAGE --------->
    <cfloop from="1" to="#form.numberOfQuestions#" index="row">
    <!--- copy values into local variables --->
    <cfset currentQuestionID = form["questionID"& row]>
    <cfset currentAnswer = form["answer"& row]>

    <!--- replace this debug output with your insert query --->
    <cfoutput>
    Row [#row#]: QuestionID = #currentQuestionID#<br>
    Row [#row#]: Answer = #currentAnswer#<br><br>
    </cfoutput>

    </cfloop>



    mxstu Guest

  4. #3

    Default Re: Dynamic <INPUT name=" "> attributes

    Awesome!

    Thanks mxstu, this is just the technique I needed.
    MajikMerlin Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139