• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

cfscript-getElementById

Participant ,
Jan 17, 2007 Jan 17, 2007

Copy link to clipboard

Copied

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}



TOPICS
Advanced techniques

Views

2.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 17, 2007 Jan 17, 2007

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 18, 2007 Jan 18, 2007

Copy link to clipboard

Copied

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...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jan 18, 2007 Jan 18, 2007

Copy link to clipboard

Copied

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:

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 19, 2007 Jan 19, 2007

Copy link to clipboard

Copied

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jan 19, 2007 Jan 19, 2007

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 19, 2007 Jan 19, 2007

Copy link to clipboard

Copied

Can you be more clear...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jan 19, 2007 Jan 19, 2007

Copy link to clipboard

Copied

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 20, 2007 Jan 20, 2007

Copy link to clipboard

Copied

Thank you Michael..tc

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 22, 2007 Jan 22, 2007

Copy link to clipboard

Copied

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 22, 2007 Jan 22, 2007

Copy link to clipboard

Copied

LATEST
This is closed.Thank u all.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation