?
Solved

Dynamic input box names

Posted on 2003-03-28
30
Medium Priority
?
215 Views
Last Modified: 2013-12-24
Hi,

I'm dynamically naming my cfform input boxes inside a query populated table, like so:
<table border="1">
<cfoutput query="get_equipment">

   <tr>
   <td><input name="Checkbox#currentrow#" type=checkbox></td>
   <td><input name="CLIN#currentrow#" value="#CLIN#" readonly></td>
   <td><input name="Part_Num#currentrow#" value="#Part_Num#" readonly></td>
   <td><input name="Manufacturer#currentrow#" value="#Manufacturer#" readonly></td>
   <td><input name="Component#currentrow#" value="#Component#" readonly></td>
   <td><input name="UNIT_PRICE_YR12#currentrow#" value="$#UNIT_PRICE_YR12#" readonly></td>
   </tr>

</cfoutput>
</table>

My problem is, I can't figure out how to pass the different input names into a database, or even have them display on the screen for that matter.  On my action page, I was trying something like:

#FORM.CLIN#currentrow##

but, that obviously doesn't work.

Any ideas?
0
Comment
Question by:FatRob
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 12
  • 5
  • 3
  • +5
30 Comments
 
LVL 8

Expert Comment

by:TallerMike
ID: 8226090
Either loop through form.fieldNames or send the maxrow to the processing page, and loop from one to that number appending it to the names just like you did with currentrow
0
 
LVL 2

Expert Comment

by:weeezl
ID: 8226206
Just run the query again before your database insert:

<cfif isdefined("form.fieldnames")>

<!--- run query here --->

<cfoutput query="get_equipment">

<cfquery name=insert datasource="dsn">
INSERT into table (CLIN,Part_Num)
VALUES (CLIN#currentrow#,Part_Num#currentrow#)
</cfquery>

</cfoutput>
</cfif>

It actually might be better to use the primary key of the entry insead of the currentrow as the dynamic variable so you can reference that value for database updates.

<cfquery name=update datasource="dsn">
UPDATE table set CLIN=CLIN#id#
where id=#id#
</cfquery>
0
 
LVL 7

Expert Comment

by:a1programmer
ID: 8226476
' this will show you the field names


<CFLOOP INDEX="ListIndex" list="#FORM.FieldNames#">
     <cfoutput>#ListIndex#</cfoutput><br>
</CFLOOP>


just insert it into the query like so...
insert into table (your_field_names) values ('#FORM.FieldNames#')


Form.FieldNames is a comma delimited list... so as long as you write the rest of your sql statement properly, this should work fine...
0
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 

Author Comment

by:FatRob
ID: 8226752
I guess I should have mentioned that the checkbox will determine if the row will be sent to the db.  So, I don't want to rename everything if I don't have to.
0
 

Author Comment

by:FatRob
ID: 8226926
In addition, the query gives me a "column not allowed here" error if I leave out the ## surrounding the Values, but also blows up if I have the extra #'s like #CLIN#currentrow##
0
 
LVL 8

Expert Comment

by:TallerMike
ID: 8226958
The following is not valid:

#CLIN#currentrow##

You need to do the following:

Evaluate("form.CLIN" & currentrow)
0
 
LVL 7

Expert Comment

by:a1programmer
ID: 8226984
Why not send in currentrow as a hidden field, and change the input values, not the names?
0
 

Author Comment

by:FatRob
ID: 8227039
where do I use Evaluate("form.CLIN" & currentrow) ?

Inside the query?  That tells me I'm missing right paren, but I'm not.
0
 

Author Comment

by:FatRob
ID: 8227074
where do I use Evaluate("form.CLIN" & currentrow) ?

Inside the query?  That tells me I'm missing right paren, but I'm not.
0
 
LVL 8

Expert Comment

by:TallerMike
ID: 8227102
If you're using weeezls code, then it would be like this:

<cfoutput query="get_equipment">

<cfquery name=insert datasource="dsn">
INSERT into table (CLIN,Part_Num)
VALUES
  (
  #Evaluate("form.CLIN" & currentrow),
  #Evaluate("form.Part_Num" & currentrow)
  )
</cfquery>

</cfoutput>

Paste your entire query and the entire error so we can determine the problem.
0
 

Author Comment

by:FatRob
ID: 8227188
<cfif isdefined("form.fieldnames")>

<cfquery name="get_equipment" datasource="RobTest" dbtype="Oracle80">
SELECT *
FROM RobTest.Equipment
</cfquery>

<cfoutput query="get_equipment">

<cfquery name="insert" datasource="RobTest" dbtype="Oracle80">
INSERT INTO RobTest.TO_EQUIP
(TASK_ORDER_NUMBER,
CLIN)
VALUES
(#Task_Order_Number#,
#Evaluate("FORM.CLIN" & currentrow))
</cfquery>

</cfoutput>
</cfif>

Error:
Just in time compilation error

Invalid parser construct found on line 19 at position 36. ColdFusion was looking at the following text:

)

Invalid expression format. The usual cause is an error in the expression structure.
The last successfully parsed CFML construct was static text occupying document position (18:21) to (18:1).
0
 
LVL 7

Expert Comment

by:a1programmer
ID: 8227198
you forgot the closing # on Evaluate

#Evaluate("FORM.CLIN" & currentrow)# )
0
 

Author Comment

by:FatRob
ID: 8227235
even with extra #, error is:

Oracle Error Code = 917

ORA-00917: missing comma

The error occurred while processing an element with a general identifier of (CFQUERY), occupying document position (13:1) to (13:62).

0
 
LVL 6

Expert Comment

by:dash420
ID: 8229271
for text box try to get the value like this

<cfif isDefined("form.CLIN#i#") and #evaluate("form.CLIN"& "#i#")# is not "">
 
</cfif>

for checkbox

<cfif isDefined("form.Checkbox#i#")>

</cfif>

there should be cfoutput enclosing while checking this condition.

regards,
Dash
0
 
LVL 11

Expert Comment

by:hart
ID: 8229480
tallermike's correct, just pass the recordcount using an hidden field to the next page.

and then on the db interaction page

<cfloop from="1" to="#hiddenfieldname#" index="ctr">
   <cfquery>

     INSERT INTO RobTest.TO_EQUIP
     (TASK_ORDER_NUMBER,CLIN)
     VALUES (#Task_Order_Number#,
     <cfif IsDefined('CLIN#ctr#') and Evaluate("Clin#ctr#") neq ''>
        #Evaluate("Clin#ctr#")#
     </cfif>    
   </cfquery>
</cfloop>
0
 
LVL 6

Expert Comment

by:dash420
ID: 8230087
any problem there. I just gives how to achieve it.

<cfquery datasource="dsn">
   insert into Table ( A , B) Values
   <cfif isDefined("form.CLIN#i#") and #evaluate ("form.CLIN"& "#i#")# is not "">
  '#evaluate ("form.CLIN"& "#i#")#'
<cfelse>
   null
</cfif>
,

<!--- This for Check Box --->
<cfif isDefined("form.Checkbox#i#")>
   'Y'
<cfelse>
   'N'
</cfif>
)
 
</cfquery>

Let me know if it is work for you.

Regards,
Dash

0
 

Author Comment

by:FatRob
ID: 8230656
Thanks everyone for your help.  But, I'm still getting the error:

Oracle Error Code = 917

ORA-00917: missing comma

How is this possible?

<cfloop from="1" to="#Tot_Rows#" index="ctr">

     <cfquery name="insert" datasource="RobTest" dbtype="Oracle80">
     INSERT INTO RobTest.TO_EQUIP
     (TASK_ORDER_NUMBER,
     CLIN)
     VALUES
     (#Task_Order_Number#,
     <cfif isDefined("form.Checkbox#ctr#")>
          <cfif IsDefined('CLIN#ctr#') and Evaluate("CLIN#ctr#") is not "">
          #Evaluate("Clin#ctr#")#)
          </cfif>
    </cfif>
     </cfquery>
     </cfloop>
0
 
LVL 17

Expert Comment

by:anandkp
ID: 8231260
hi replace ur code with this !

<cfloop from="1" to="#Tot_Rows#" index="ctr">

    <cfquery name="insert" datasource="RobTest" dbtype="Oracle80">
    INSERT INTO RobTest.TO_EQUIP
    (TASK_ORDER_NUMBER,
    CLIN)
    VALUES
    (#Task_Order_Number#,
    <cfif isDefined("form.Checkbox#ctr#")>
         <cfif IsDefined('CLIN#ctr#') and Evaluate("CLIN#ctr#") is not "">
         #Evaluate("Clin#ctr#")#)
         <cfelse>
          NULL
         </cfif>
   <cfelse>
    NULL
   </cfif>
    </cfquery>
    </cfloop>

hope this works

K'Rgds
Anand
0
 
LVL 6

Expert Comment

by:dash420
ID: 8236294
Try this

<cfloop from="1" to="#Tot_Rows#" index="ctr">

    <cfquery name="insert" datasource="RobTest" dbtype="Oracle80">
    INSERT INTO RobTest.TO_EQUIP
    (TASK_ORDER_NUMBER,
    CLIN)
    VALUES
    (#Task_Order_Number#,
    <cfif isDefined("form.Checkbox#ctr#") and IsDefined('CLIN#ctr#') and Evaluate("CLIN#ctr#") is not "">
      #Evaluate("Clin#ctr#")#
   <cfelse>
      NULL
   </cfif>
)
</cfquery>
</cfloop>
0
 
LVL 11

Expert Comment

by:hart
ID: 8236444
first of all are both these fields numeric

i.e TASK_ORDER_NUMBER & CLIN

And also check wether this value #Evaluate("Clin#ctr#")#
has comma in it. If it has then it cannot be numeric.

Sometimez the error is shown when there are more commas also.

Also check the braces wether they are closing properly or not.

or try this out

<cfloop from="1" to="#Tot_Rows#" index="ctr">

    <cfquery name="insert" datasource="RobTest" dbtype="Oracle80">
    INSERT INTO RobTest.TO_EQUIP
    (TASK_ORDER_NUMBER
    <cfif isDefined("form.Checkbox#ctr#")>
         <cfif IsDefined('CLIN#ctr#') and Evaluate("CLIN#ctr#") is not "">,CLIN</cfif>
   </cfif>)
    VALUES
    (#Task_Order_Number#
    <cfif isDefined("form.Checkbox#ctr#")>
         <cfif IsDefined('CLIN#ctr#') and Evaluate("CLIN#ctr#") is not "">
         ,#Evaluate("Clin#ctr#")#)
         </cfif>
   </cfif>
    </cfquery>
    </cfloop>

let me know...

Regards
Harish(hart)
0
 

Author Comment

by:FatRob
ID: 8238963
I've checked all values and no commas exist.
I've tried each piece of code above and all give same "comma" error.
0
 
LVL 10

Expert Comment

by:substand
ID: 8239786
one thing you may be having trouble with:

,#Evaluate("Clin#ctr#")#)

try:

<cfset tempvar=Evaluate("Clin#ctr#")>
then

,#tempvar#)

also, here is another problem.. actually, i'll just post the revised code:

<cfloop from="1" to="#Tot_Rows#" index="ctr">

   <cfquery name="insert" datasource="RobTest" dbtype="Oracle80">
   INSERT INTO RobTest.TO_EQUIP
   (TASK_ORDER_NUMBER
   <cfif isDefined("form.Checkbox#ctr#")>
        <cfif IsDefined('CLIN#ctr#') and Evaluate("CLIN#ctr#") is not "">,CLIN</cfif>
  </cfif>)
   VALUES
   (#Task_Order_Number#
   <cfif isDefined("form.Checkbox#ctr#")>
        <cfif IsDefined('CLIN#ctr#') and Evaluate("CLIN#ctr#") is not "">
        <cfset tempvar=Evaluate("Clin#ctr#")>
        ,#tempvar#
        </cfif>)
  </cfif>
   </cfquery>
   </cfloop>


0
 
LVL 10

Expert Comment

by:substand
ID: 8239821
the main problem i saw that will definitely mess it up (which i fixed in the above code) was that you had basically set up the code where it could produce the query:

Insert into tablename (column1) values (value 1


and not put the last paren on. this might have caused oracle to be looking for a comma.

0
 

Author Comment

by:FatRob
ID: 8239928
substand,

Sorry, I still get the same error.  Maybe you can help me do this another way?  What I am doing is I have a query that returns a list of equipment displayed in a table.  The amount of rows returned is always different, thus the reason for dynamically naming the input boxes.  The first column in the table is a checkbox.  I want the user to be able to check each piece of equipment they need and then when they hit submit, it will store the equipment info in the database.  I thought what I was doing was OK, but it seems that this problem is beyond help.
0
 
LVL 10

Accepted Solution

by:
substand earned 300 total points
ID: 8240006
no, it is ok.  i didn't want to write code over and steal someone else's glory if it was as simple as what i saw upon first glance.  here's what I would do:

on the select page:

<table border="1">
<tr><td colspan="6">
Check the box next to the equipment you need.
</td>
</tr>
<cfoutput query="get_equipment">

  <tr>
  <td><input name="listofitems" value="#currentRow# type=checkbox></td>
  <td><input name="CLIN#currentrow#" value="#CLIN#" readonly></td>
  <td><input name="Part_Num#currentrow#" value="#Part_Num#" readonly></td>
  <td><input name="Manufacturer#currentrow#" value="#Manufacturer#" readonly></td>
  <td><input name="Component#currentrow#" value="#Component#" readonly></td>
  <td><input name="UNIT_PRICE_YR12#currentrow#" value="$#UNIT_PRICE_YR12#" readonly></td>
  </tr>

</cfoutput>
</table>


then, when the form is submitted, handle it using this:

<cfloop list="#form.listofitems#" index="#cr#">

<cfquery name="insert" datasource="RobTest" dbtype="Oracle80">

INSERT INTO RobTest.TO_EQUIP
(TASK_ORDER_NUMBER, CLIN)
VALUES
(#Task_Order_Number#, #Evaluate("FORM.CLIN" & cr)#)
</cfquery>

</cfloop>

if TASK_ORDER_NUMBER is a self-incrementing field, then make sure not to insert it.

try that and let me know.  going this route will also save alot of processing in the <cfif>'s and such.

0
 

Author Comment

by:FatRob
ID: 8240152
TASK_ORDER_NUMBER is actually a session variable based on a previous page.

In your code, I took out the ## around cr in index="#cr#".

But, then I am still getting the same comma error!
0
 

Author Comment

by:FatRob
ID: 8240239
Hey, this did the trick: '#Evaluate("Clin" & "#cr#")#'

Thanks!
0
 

Author Comment

by:FatRob
ID: 8240246
I appreciate all of everyone's help!
0
 
LVL 10

Expert Comment

by:substand
ID: 8240267
ok.  sorry about the #'s around the cr.  glad you noticed it.

I've got a couple of questions then:

1) do you have any constraint on the table columns where it might be expecting a comma?

2) are the fields that you are inserting the only fields in that table?  

3) can you try taking out the "(TASK_ORDER_NUMBER, CLIN)
VALUES" of the query?  if that doesn't work, just put in "VALUES" and take out the column names.

I remember something wierd about doing inserts in oracle, and it had to do with something like that.

0
 
LVL 10

Expert Comment

by:substand
ID: 8240281
oh, ok.  thats funny, and makes a whole bunch of sense now that i think about it.
0

Featured Post

How Blockchain Is Impacting Every Industry

Blockchain expert Alex Tapscott talks to Acronis VP Frank Jablonski about this revolutionary technology and how it's making inroads into other industries and facets of everyday life.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question