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

Copy form field values

New Here ,
May 08, 2006 May 08, 2006

Copy link to clipboard

Copied

I am running a query to create a dynamic form. I want to copy the values in one field to another. So far I have this.

### JAvascript part###
<script language="JavaScript">
var bCopy = true;
function doCopy() {
for(i=1; i<100; i++) {
document.getElementById('rec'+i).value = document.getElementById('ord'+i).value;
}
}

function doClear() {
for(i=1; i<100; i++) {
document.getElementById('rec'+i).value = 0;
}
}

function doAction() {
if(bCopy) {
doCopy();
bCopy = false;
} else {
doClear();
bCopy = true;
}
}

</script>

### CFM part###

<td><b>Qty</b></td>
<td><b><a href=# onClick="doAction();">Rec</a></b></td>

<cfoutput query="Details">
<td><input class="input_text" type="hidden" id="ord#CurrentRow#" name="OLD_QTY_ORDERED#CurrentRow#" value="#QTY_ORDERED#"></td>
<td><cfinput type="text" id="rec#CurrentRow#" name="QTY_RECEIVED#CurrentRow#" value="#NumberFormat(QTY_RECEIVED)#"></td>
###end###

I want to toggle the value of the second field between the values of the first field and '0' by clicking on the column header.

2 questions
the first part works, but it does not toggle back to 0.
how to pass the recordcount into the loop
TOPICS
Advanced techniques

Views

960

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
Enthusiast ,
May 09, 2006 May 09, 2006

Copy link to clipboard

Copied

You should make this independant of the cf query, you can do this by looping through the document elements

Note:
replace "formName" with the name of your form

<script language="JavaScript">
var bCopy = true;
function doCopy() {
// loop through the document elements
for(i=0; i<document.formName.elements.length; i++) {
// find the element name (id)
elementName = document.formName.elements .name;
// extract the appended index of the element
elementIndex = elementName.substring(4,elementName.length);
if(elementName.indexOf('rec')){
document.formName.elements
.value = document.getElementById('ord' + elementIndex).value;
}
}
function doClear() {
for(i=0; i<document.formName.elements.length; i++) {
elementName = document.formName.elements .name;
if(elementName.indexOf('rec')){
document.formName.elements
.value = 0;
}
}
</script>
Note this code is untested.

Ken

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
New Here ,
May 10, 2006 May 10, 2006

Copy link to clipboard

Copied

Thanks Scare Crow - this part definitely helped
for(i=0; i<document.formName.elements.length; i++)

I am still not getting it to toggle back to '0'

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
LEGEND ,
May 09, 2006 May 09, 2006

Copy link to clipboard

Copied

Have you thought about not copying the values at all? Just use the existing fields twice when you process the form.

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
New Here ,
May 10, 2006 May 10, 2006

Copy link to clipboard

Copied

Dan - do you mean do the query again and reload the page after checking for a variable and then fill in the values using CF?

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
Enthusiast ,
May 10, 2006 May 10, 2006

Copy link to clipboard

Copied

The code I posted has some errors in it.
I also noticed that you have a different "name" and "id" value for the form fields !!

But here is a working example

Ken

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
New Here ,
May 12, 2006 May 12, 2006

Copy link to clipboard

Copied

Used the same ID's and NAMES and now with your new code, it works. Thanks ScareCrow!

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
LEGEND ,
May 12, 2006 May 12, 2006

Copy link to clipboard

Copied

quote:

Originally posted by: freezer9
Dan - do you mean do the query again and reload the page after checking for a variable and then fill in the values using CF?

This is what I mean. You start by saying this:
I am running a query to create a dynamic form. I want to copy the values in one field to another. So far I have this.

For the sake of simplicity let's say there are only two fields, f1 and f2. You have a value in f1 and you want f2 to either have the same value or be equal to 0. At least that's how I understand it.

You are currently using a javascript onclick event to control the value of f2. This is hard, hence your difficulties. An easier way is to get rid of f2. Add a check box or radio button for the user input.

When you submit your form, you want two variables. You already have the first one, form.f1. The second one either has to equal form.f1 or has to be 0. Assign that value based on what the user did with the check box or radio button.

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
New Here ,
May 12, 2006 May 12, 2006

Copy link to clipboard

Copied

LATEST
Thanks Dan - I understand it now. That would work except that it is not an "all or nothing" situation always. It is just like if you are looking at your junkmail folder - you want to delete all the 50 messages that you see in that page, expect, may be 1 or 2 - you, would then click on the checkbox, and then 'un-select' only the ones that you don't want to delete. I am trying to accomplish something like that without using the checkbox on each row. So here with the solution that SCARECROW gave, I am able to let the user automatically fill in the values for most of the rows, and then 'zero' out some manually. Sorry for not explaining in detail.
Thanks guys!

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