CF - One form value fills another field value

JohnMac328
JohnMac328 used Ask the Experts™
on
Right now it is manually done and does work.  I would like the credit earned field to automatically fill in either 1 or 0 based on the value in test status, either passed or Failed.  Any help is appreciated.
<tr>
         <td><select name="Test_Status">
            <option value='1'#UserPass#>Passed</option>
            <option value='0'#UserFail#>Fail</option>
        </select></td>
        <td><cfinput type="datefield" name="Test_Date"></td>
        <td><select name="Credits_Earned" class="widthed">
            <option value='0'>0</option>
            <option value='1'>1</option>
            </select></td>
      </tr>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
erikTsomikSystem Architect, CF programmer

Commented:
can u be more specific for what r u trying to do

Author

Commented:
When the value of test status is selected, either a 1 or 0, then based on that the credit field will fill in with a 1 or 0

1 = Passed and then the credit field will be 1 and the opposite for Failed which is 0
erikTsomikSystem Architect, CF programmer

Commented:
i would do it with javascript
take a look at this here
http://www.plus2net.com/javascript_tutorial/dropdown-list-demo.php
How to Generate Services Revenue the Easiest Way

This Tuesday! Learn key insights about modern cyber protection services & gain practical strategies to skyrocket business:

- What it takes to build a cloud service portfolio
- How to determine which services will help your unique business grow
- Various use-cases and examples

Author

Commented:
The link example does not work.  When the category value is selected, the sub cat value never changes.
erikTsomikSystem Architect, CF programmer

Commented:
it does work . at least it will give you an idea how to do it . just right click on the screeen and select View Source

Author

Commented:
I did copy the source, I was curious why the value in the second drop-down never changed when the value in the first drop-down is selected.  I will put it in and see what happens.

Author

Commented:
Subcat dropdown never changes value
see how this works, this uses your code above...
<script>
//if coldfusion pre-selects an option, this will adjust the credit field when the page loads 
window.onload = function(){
  var updateThisOnload = document.getElementById("status");
  updateCredits(updateThisOnload, "credits");
 }
 
//update credit field based on status field
 function updateCredits(obj, creditFieldId){
  var selectedValue = obj.options[obj.selectedIndex].value;
  var creditField = document.getElementById(creditFieldId);
  
  for(var i = 0; i < creditField.options.length; i++){
   creditField.options[i].selected = (creditField.options[i].value == selectedValue) ? true : false;
  }
  
 }
</script>

<tr>
         <td><select id="status" name="Test_Status" onChange="updateCredits(this, 'credits');">
            <option value='1'#UserPass#>Passed</option>
            <option value='0'#UserFail#>Fail</option>
        </select></td>
        <td><cfinput type="datefield" name="Test_Date"></td>
        <td><select id="credits" name="Credits_Earned" class="widthed">
            <option value='0'>0</option>
            <option value='1'>1</option>
            </select></td>
      </tr>

Open in new window

Author

Commented:
Great, thanks
Glad I could help, thanks!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial