0
cfscript-getElementById
Participant
,
/t5/coldfusion-discussions/cfscript-getelementbyid/td-p/711200
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}
<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
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Contributor
,
/t5/coldfusion-discussions/cfscript-getelementbyid/m-p/711201#M66631
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.
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.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
emmim44
AUTHOR
Participant
,
/t5/coldfusion-discussions/cfscript-getelementbyid/m-p/711202#M66632
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...
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...
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Advocate
,
/t5/coldfusion-discussions/cfscript-getelementbyid/m-p/711203#M66633
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:
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:
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
emmim44
AUTHOR
Participant
,
/t5/coldfusion-discussions/cfscript-getelementbyid/m-p/711204#M66634
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>
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>
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Advocate
,
/t5/coldfusion-discussions/cfscript-getelementbyid/m-p/711205#M66635
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.
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.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
emmim44
AUTHOR
Participant
,
/t5/coldfusion-discussions/cfscript-getelementbyid/m-p/711206#M66636
Jan 19, 2007
Jan 19, 2007
Copy link to clipboard
Copied
Can you be more clear...
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Advocate
,
/t5/coldfusion-discussions/cfscript-getelementbyid/m-p/711207#M66637
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>
<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>
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
emmim44
AUTHOR
Participant
,
/t5/coldfusion-discussions/cfscript-getelementbyid/m-p/711208#M66638
Jan 20, 2007
Jan 20, 2007
Copy link to clipboard
Copied
Thank you Michael..tc
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
emmim44
AUTHOR
Participant
,
/t5/coldfusion-discussions/cfscript-getelementbyid/m-p/711209#M66639
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
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>
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
emmim44
AUTHOR
Participant
,
LATEST
/t5/coldfusion-discussions/cfscript-getelementbyid/m-p/711210#M66640
Jan 22, 2007
Jan 22, 2007
Copy link to clipboard
Copied
This is closed.Thank u all.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

