Solved

Data population in Cold Fusion

Posted on 2014-02-09
3
215 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

809 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