Solved

Data population in Cold Fusion

Posted on 2014-02-09
3
212 Views
Last Modified: 2014-02-27
Category DropdownHi,
  I have a CFM page where I list Category along with CategoryID in the drop down.
  I like to be able to populate Category ID (in parenthesis) in the Category ID field when user selects the category from the drop-down menu.
  For example, when the user selects "Picture Frames", then I want the page to populate 23 automatically into Category ID field as seen in the screenshot above.
  Here are the codes in my CFM page

<CFQUERY NAME="GetCategory" datasource="DNSName" cachedWithin="#CreateTimeSpan(0,1,0,0)#">
      SELECT      *
         FROM         Category
      ORDER BY Category
</CFQUERY>

    <TR bgcolor="B5D083">
        <TD>
           Category ID:
        </TD>
        <TD>
      <CFINPUT TYPE="text" NAME="CategoryID" SIZE=3 MAXLENGTH=3> Category Lookup:
                  <SELECT NAME="CategoryID">
                    <OPTION VALUE="0"></OPTION>
                  <CFOUTPUT query="GetCategory">
                  <OPTION VALUE="#ID#">#Category#/(#ID#)</OPTION>
                  </CFOUTPUT>
                  </SELECT>        </TD>
    </TR>
0
Comment
Question by:sglee
3 Comments
 
LVL 19

Accepted Solution

by:
erikTsomik earned 158 total points
Comment Utility
I think the best approach will be using jquery to create on change event

$("#CategoryID).change(function(){
   $("#CategoryID").val($(this).val());
})

or something like this. Make sure that the id is spelled correctly. Because jquery is a case sensitive
0
 

Author Comment

by:sglee
Comment Utility
@erikTsomik
Where exactly I need to insert the code above?
0
 
LVL 52

Assisted Solution

by:_agx_
_agx_ earned 157 total points
Comment Utility
It's JQuery code, so put it inside document.ready. But for Erik's example to work, both fields must have an "ID".  (Also fixed a small typo).  To avoid confusion, use different id's like in the <form> below:

<script type"text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
      $(document).ready(function() {
            $("#CategoryID").change(function() {
                  $("#SelectedCategoryID").val($(this).val());
            });
            
      });
</script>
<form>
      Selected Category <input type="text" id="SelectedCategoryID" name="SelectedCategoryID"><br>
      All Categories <select id="CategoryID" name="CategoryID">
      <cfoutput query="getCategory">
            <option value="#ID#">#Category# (#ID#)</option>
      </cfoutput>
      </select>
</form>
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now