10 Replies Latest reply on Jan 22, 2007 2:42 PM by emmim44

    cfscript-getElementById

    emmim44 Level 1
      I have a form object that contains a list of items in it.I want to loop over it and get each item and then update the in db..but below code doesnt do it..smth is not right ? any help will be app..Thx all.

      <input name="act" type="text" size="10" maxlength="20" style="height:19px; font-family:Arial, Helvetica, sans-serif" value="" id="#f1#|#f2#"/>
      sample:
      Form.act={BBT|10A-10P,CB|10A-10P,BBT|10P-10A,...etc}



        • 1. Re: cfscript-getElementById
          dempster Level 1
          It looks like you're using JavaScript inside your CFSCRPT block. That won't work.

          If form.act is a list, use a list loop instead of an index loop.

          <CFLOOP INDEX="oneitem" LIST="#Form.act#">
          </CFLOOP>

          The first value of oneitem is BBT|10A-10P, the second CB|10A-10P,etc.
          • 2. Re: cfscript-getElementById
            emmim44 Level 1
            The problem is not there...The problem is I cannot get the value of ID along with the value of form.act...
            Example:
            <input name="act" type="text" size="10" maxlength="20" style="height:19px; font-family:Arial, Helvetica, sans-serif" value="Aron Gock" id="#f1#|#f2#"/>

            I may have many text boxes like above with different value ...I want to insert the value of txt box into a db field after matching the Id value...
            • 3. cfscript-getElementById
              insuractive Level 3
              It looks like you have a few problems in your code. First off, dempster is right about your <cfscript> block. getElementById() is not a valid coldfusion function. If you want the value of the Form element, just use Form["myField"] instead of getElementById("Form.myField").value

              Now on to your main issue - The ID attribute of the text field does not transmit to the action page when the form is submitted. The only attribute that does that is the VALUE attribute. The ID attribute is intended to allow javascript to identify and reference the tag on the form page. If you want to transmit data other than the values that are in the VALUE="" attribute, you will have to do so with hidden form fields. Example:
              • 4. Re: cfscript-getElementById
                emmim44 Level 1
                I want to transmit the value of text fields...in to db ..means I want to update the table by matching with the name of hidden field but the thing is some of the text boxes might be blank ...how you gonna ctrl that..
                example:
                say you have 4 different txt boxes with value Elma,armut,kela,sela...and your 4 hidden fields carry these values BBT|6A-6P, BBT|6A-6P, BBT|6A-6P,QMT|10A-10P......The user will enter the value of Txt boxes...Then how u gonna update this table...

                <cfset Fac=listgetat(Form.actV,q)>
                <cfset Fc=listgetat(BBT|6A-6P,1,"|")>
                <cfset Fs=listgetat(BBT|6A-6P2,"|")>
                <cfquery name="gethomefacTmp" datasource="#FormVector#">
                update GENBID_BIDRESULT
                set
                ActName='#actFn#'

                where facname='#Fc#' and facsch= '#Fs#'

                </cfquery>

                • 5. cfscript-getElementById
                  insuractive Level 3
                  Then you'll have to use the NAME of the textboxes to link the hidden fields to the textbox, not the VALUE. The name should never be empty. You can set a custom prefix for each of the fields you want to pass, and then loop through Form.FieldNames and only process fields that have that prefix.

                  Oh, on a side note, you can use ListFirst(myList, "|") and ListRest(myList, "|") instead of
                  <cfset Fc=listgetat(BBT|6A-6P,1,"|")>
                  <cfset Fs=listgetat(BBT|6A-6P,2,"|")>
                  Might be a little faster.
                  • 6. Re: cfscript-getElementById
                    emmim44 Level 1
                    Can you be more clear...
                    • 7. Re: cfscript-getElementById
                      insuractive Level 3
                      Instead of naming all the textboxes the same thing (i.e. act), give them all different names with some identifying prefix or suffix:

                      <input name="act_1" type="text" size="10" maxlength="20" style="height:19px; font-family:Arial, Helvetica, sans-serif" value="Aron Gock"/>

                      then pass hidden fields associated with that textbox:

                      <input type="hidden" name="act_1_fc" value="BBT">
                      <input type="hidden" name="act_1_fs" value="6A-6P">

                      On your processing page, loop over the Form.Fieldnames and only process fields that match your naming scheme:

                      e.g.
                      <!--- loop over submitted fields --->
                      <cfloop list="#Form.FieldNames#" index="field">
                      <!--- only process fields that start with "act_" i.e. act_1, act_2, etc --->
                      <cfif FindNoCase("act_", field)>
                      <!--- Set values from form --->
                      <cfset fac = FORM[field]
                      <cfset fc = FORM["#field#_fc"]>
                      <cfset fs = FORM["#field#_fs"]>

                      <!--- Processing/DB code here --->

                      </cfif>
                      </cfloop>
                      • 8. Re: cfscript-getElementById
                        emmim44 Level 1
                        Thank you Michael..tc
                        • 9. Re: cfscript-getElementById
                          emmim44 Level 1
                          So far it works.. The thing is : if I have a text box value and two corresponding hidden fields.. it updates all the matched records in db..
                          Example:
                          Text box value= Aron yunus
                          the value of Hidden fc=QMT
                          the value of Hidden fs=10A-10P

                          And the db has two such records with different unique ID..it updates both instead of updating one record...

                          here is my code:

                          <cfloop index="q" list="#form.FieldNames#">


                          <cfif (q DOES NOT CONTAIN "_fs" and q DOES NOT CONTAIN "_fc" ) and Form["#q#"] neq "" and q neq "sb">

                          <cfset fac=Form
                          quote:

                          >
                          <cfset fc=Form["#q#_fc"]>
                          <cfset fs=Form["#q#_fs"]>

                          <cfquery name="gethomefacTmp" datasource="#FormVector#">
                          update GENBID_BIDRESULT
                          set
                          ActName='#fac#'

                          where facname='#fc#' and facsch= '#fs#'

                          </cfquery>

                          <cfset form.FieldNames=listdeleteat(Form.FieldNames,Listfindnocase(form.FieldNames,q))>
                          <cfoutput>#form.fieldNames# -Fac:#q#</cfoutput>
                          </cfif>




                          </cfloop>
                          • 10. Re: cfscript-getElementById
                            emmim44 Level 1
                            This is closed.Thank u all.