Welcome to Dream.In.Code
Become an Expert!

Join 136,874 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,680 people online right now. Registration is fast and FREE... Join Now!




Dynamicly created text fields and getting them into a db

 
Reply to this topicStart new topic

Dynamicly created text fields and getting them into a db, Not sure that is a good description

wblakenc
23 Jul, 2008 - 11:42 AM
Post #1

New D.I.C Head
*

Joined: 17 Jul, 2008
Posts: 6



Thanked: 1 times
My Contributions
Ok I am working on an online form where counties in my state can enter in data based on the number of precincts they have. I have it currently when the county logs on that CF populates a table and creates text input fields so the user can type in the data. The problem is, each county has a different number of precincts so how to i insert fields into a database if I do not know how many text fields their will be. The number varies greatly (some have 4 others have 198).

For example (what the county will see)

Precinct 1 - [text input field 1]
Precinct 2 - [text input field 2]

[...]

Precinct x - [text input field x]


Like I said I already have the precincts stored in a database and when the form is generated by CF it puts the precinct names into the form for the county. But how do I save the user input?

I was thinking of putting the text input into an array using javascript, but I do not know how to loop through all the text fields easily.

Currently here is my code:

CODE


<table>
<cfinput type="text" name="modemNums" value="#popModem.recordCount#">
<cfoutput query="popModem">
<tr>
<td><cfinput type="text" name="precinct#popModem.currentRow#" value="#precinct#" readonly="true"></td><td><cfinput type="text" name="phone#popModem.currentRow#"></td>
</tr>
</cfoutput>
</table>


Ideas?!?
User is offlineProfile CardPM
+Quote Post

imamkomc
RE: Dynamicly Created Text Fields And Getting Them Into A Db
15 Nov, 2008 - 05:44 AM
Post #2

D.I.C Head
Group Icon

Joined: 9 May, 2007
Posts: 62


Dream Kudos: 225
My Contributions
Try like This code,
CODE

<!--- initialitation variables --->
<cfset noso=ArrayNew(1)>
<cfparam name="xxx" default="">
<cfloop  from="1" to="#query_name.recordcount#" index="i">
    <cfset form.noso[i]=25 + #i#>
</cfloop>

<cfif isDefined('Save')> <!--- if button "save" OnKeyUp --->
<cfoutput query="query_name">
  <table width="100%"  border="1" cellspacing="0" cellpadding="0" id="border">
    <cfinput name="xxx" type="text" value="#ListGetAt(xxx,currentrow)#" size="10" >
</cfoutput>
<cfelse>
<cfoutput query="query_name"> <!--- Onload --->
   <table width="100%"  border="1" cellspacing="0" cellpadding="0" id="border">
    <cfinput name="xxx" type="text" value="#form.noso[currentrow]#" size="10" >
  </cfoutput>
</cfif>

<cfloop query="query_name"> <!--- to display your variable as currentrow --->
  <td  align="center" valign="middle"> <cfoutput>#ListGetAt(xxx,currentrow)#</cfoutput></td>
</cfloop>


Best Regard,
ImamkomC
User is offlineProfile CardPM
+Quote Post

danny83
RE: Dynamicly Created Text Fields And Getting Them Into A Db
21 Nov, 2008 - 08:31 AM
Post #3

New D.I.C Head
*

Joined: 21 Nov, 2008
Posts: 4

Hiya,

just perform the same select as you do on the form, and update the corresponding records smile.gif

Display Form
CODE

<table>
    <cfinput type="text" name="modemNums" value="#popModem.recordCount#">
    <cfoutput query="popModem">
        <tr>
            <td><cfinput type="text" name="precinct#popModem.currentRow#" value="#precinct#" readonly="true"></td>
            <td><cfinput type="text" name="phone#popModem.currentRow#"></td>
        </tr>
    </cfoutput>
</table>



Form Action
CODE

    <cfloop query="popModem">
        <cfif IsDefined("form.phone#popModem.currentRow#")>
            <cfquery datasource="#request.MyDSN#">
                UPDATE MyTable
                SET phone = <cfqueryparam cfsqltype="cf_Sql_char" value="#form["phone#popModem.currentRow#"]#">
                WHERE MyId = <cfqueryparam cfsqltype="cf_sql_numeric" value="#popModem.MyId#">
            </cfquery>
        </cfif>
    </cfloop>

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/3/08 08:09PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month