Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Pass currently selected form field value to CFWINDOW for insert into query.

Posted on 2009-03-30
7
Medium Priority
?
1,037 Views
Last Modified: 2012-05-06
I am using CFWINDOW to add some records on the fly.  I have have 2 select boxes in a form and 1 select is a child of the other.  When I add a record to the child select using CFWINDOW, I need to pass the parent selects current value to the cfwindow so I can insert it with the new child record.  My problem is, I don't know how to pass that value to the cfwindow.  Here is what I have for code.

I need to get the value of SALE_BUYER_ID and pass it to my insert query somehow.
<!---             Index.cfm             ---->
 
<cfinclude template="addWindow.cfm">
 
<cfform name="sale">
 
<cfselect name="sale_buyer_id" id="sale_buyer_id" size="1" bind="javascript:getSaleBuyers()" bindonload="true" display="sale_buyer_Name" value="sale_buyer_id" selected="#sale.sale_buyer_id#" />
 
<br />
 
<select name="sale_buyer_yard_id" id="sale_buyer_yard_id">
</select>
 
<a href="javascript:addSaleBuyerYard();">[add new]</a>
 
</cfform>
 
 
 
<!---             addWindow.cfm             ---->
 
<cfajaximport tags="CFWINDOW, CFFORM">
<cfajaxproxy cfc="addWindow" jsclassname="salebuyeryardProxy">
 
<!--- js functions --->
<script type="text/javascript">
var openWindow = function(name,title,url,options){
 ColdFusion.Window.create(name, title, '', options);
 ColdFusion.navigate(url, name);
};
 
<!--- Functions specific to adding a new SALE BUYER YARD --->
var addSaleBuyerYard = function(){ //opens add_Salebuyeryard.cfm page in a cfwindow for adding new auction data
 ColdFusion.Window.create('sale_buyer_yard_id_window', 'Add Sub-Yard', 'add_SaleBuyerYard.cfm', {center:true,height:300,width:380,closable:true,dragable:true,resizable:true,modal:true,initshow:true});
};
 
var getSaleBuyerYards = function(){ //uses ajax proxy to populate cfselect
 var p = new salebuyeryardProxy();
 var populate = p.getSaleBuyerYards4cfselect();
 return populate;
};
 
var onHideAddSaleBuyerYard = function(name){ //refreshes the cfselect
 ColdFusion.Bind.assignValue('sale_buyer_yard_id', 'value', getSaleBuyerYards());
};
 
 
<!--- END UNIQUE FUNCTIONS --->
var onAddNewSuccess = function(name, fcn){ //my generic function to handle newly added data
 ColdFusion.Window.onHide(name, fcn);
 ColdFusion.Window.hide(name);
 var el_id = name.substr(0,name.indexOf('_window'));
 setNewSelectedOption(el_id);
};
var setNewSelectedOption = function(id){
 var el = document.getElementById(id);
 var arrV = new Array();
 for (var i=0; i<el.options.length; i++){
  arrV[i]=el.options[i].value;
  if (el.options[i].value == Math.max.apply(Math,arrV)){
   el.options[i].selected=true;
  }
 }
};
 
</script>
 
 
 
 
 
<!---             My INSERT query in the add_SaleBuyerYard.cfm page            ---->
 
<cfquery name="insert" datasource="#request.dsn#">
INSERT INTO sale_buyer_yard
(sale_buyer_id, sale_buyer_yard, sale_buyer_yard_directions)
VALUES
(#VALUE OF SALE_BUYER_ID#, '#TRIM(UCASE(FORM.sale_buyer_yard))#', '#TRIM(UCASE(FORM.sale_buyer_yard_directions))#')
</cfquery>

Open in new window

0
Comment
Question by:MFredin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 
LVL 36

Accepted Solution

by:
SidFishes earned 1000 total points
ID: 24021783
since cfwindow is simply creating a div that -looks- like a window you just need to reference the parent id (as a hidden field perhaps?)

you can also pass the value in the Window.create call add_SaleBuyerYard.cfm?parentid=whatever


0
 

Author Comment

by:MFredin
ID: 24023061
Oh perfect. Thanks!!!
0
 

Author Comment

by:MFredin
ID: 24023311
Sorry, I think I closed this question too soon.  Is there a way I could use javascript to find the current value of a select box and add it to the URL when I launch my addSaleBuyerYard(); function?  I'm not very JS savvy, so example code is needed please.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:MFredin
ID: 24023359
Since it will be grabbing a value, potentially after load since the use will most likely be changing the select box, can this still be done?  
0
 
LVL 36

Expert Comment

by:SidFishes
ID: 24023464
something like this should work


var addSaleBuyerYard = function(){

var param = document.getElementById('sale_buyer_id').value;
 ColdFusion.Window.create('sale_buyer_yard_id_window', 'Add Sub-Yard', 'add_SaleBuyerYard.cfm?sale_buyer_id' + param, {center:true,height:300,width:380,closable:true,dragable:true,resizable:true,modal:true,initshow:true});
};
0
 

Author Comment

by:MFredin
ID: 24023629
It worked!  One last question... I can create a new one so you can get the points if you want?

I want to do the same type of thing with a cfc...

Here is what my cfc code looks like with the javascript added... obviously I am missing some things.. Can you fill in the blanks so it would work?

Thanks for the help!
<!--- Sale Buyer Yards CFC to fill the cfselect query --->
<cffunction name="getSaleBuyerYards4cfselect" access="remote" returntype="query" output="false">
<cfset var qGetSaleBuyerYards="">
 
<!--- Get the current value of the parent select box to use in the query --->
var param = document.getElementById('sale_buyer_id').value;
 
<cfquery name="qGetSaleBuyerYards" datasource="#request.dsn#">
SELECT sale_buyer_yard_id, sale_buyer_yard
FROM sale_buyer_yard
WHERE sale_buyer_id = param
ORDER BY sale_buyer_yard
</cfquery>
 
<cfreturn qGetSaleBuyerYards />
</cffunction>

Open in new window

0
 

Author Comment

by:MFredin
ID: 24023640
SidFishes,

I created this similar question earlier... just add a comment and I will award the points since you answered it here.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

618 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