Solved

Data population in Cold Fusion

Posted on 2014-02-09
3
217 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
ID: 39846396
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
ID: 39846436
@erikTsomik
Where exactly I need to insert the code above?
0
 
LVL 52

Assisted Solution

by:_agx_
_agx_ earned 157 total points
ID: 39848268
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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

828 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