MFredin
asked on
Get the current value of a select box.
I need to find the current value of a select box and set it as a coldfusion variable. Whats the best way to do this?
ASKER
Sorry, I should have explained more. Please see my other post... https://www.experts-exchange.com/questions/24278303/Pass-currently-selected-form-field-value-to-CFWINDOW-for-insert-into-query.html?anchorAnswerId=24023311#a24023311
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
value="#ur;sale_buyer_id#
sb
value="#url.sale_buyer_id#
sb
value="#url.sale_buyer_id#
ASKER
Hmmm.. ok. I will explain what I am trying to do.
When I add a new Sale_Buyer_Yard using the CFWINDOW in the last question, it fires the javascript:getSaleBuyerYar ds in my cfc to refill the sale_buyer_yard_id cfselect box. What I am missing from it is the WHERE clause to tell it which sale_buyer_id. Right now its just returning all sale_buyer_yards since I have no WHERE clause. I need it to return the results WHERE sale_buyer_id = document.getElementById('s ale_buyer_ id').value . Just not sure how to do that. So I guess I need to figure out how to pass document.getElementById('s ale_buyer_ id').value to the cfc and use it in the WHERE clause.
When I add a new Sale_Buyer_Yard using the CFWINDOW in the last question, it fires the javascript:getSaleBuyerYar
<!--- Sale Buyer --->
<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#" />
<!--- Sale Buyer Yard --->
<cfselect name="sale_buyer_yard_id" id="sale_buyer_yard_id" bind="javascript:getSaleBuyerYards()" bindonload="true" display="sale_buyer_yard" value="sale_buyer_yard_id" />
ASKER
SidFishers,
Does that make sense? I upped the points on this question... it's been stumping me for days!
Does that make sense? I upped the points on this question... it's been stumping me for days!
what does your getSaleBuyerYards js function look like?
if it uses a cfc proxy, post the cfc function call as well.
Azadi
if it uses a cfc proxy, post the cfc function call as well.
Azadi
ASKER
Hi Azadi,
Do you mean my cfc?
FYI: This question is somewhat of a continuation of this question... https://www.experts-exchange.com/questions/24278303/Pass-currently-selected-form-field-value-to-CFWINDOW-for-insert-into-query.html
Do you mean my cfc?
FYI: This question is somewhat of a continuation of this question... https://www.experts-exchange.com/questions/24278303/Pass-currently-selected-form-field-value-to-CFWINDOW-for-insert-into-query.html
<!--- Sale Buyer Yards CFC to fill the cfselect query --->
<cffunction name="getSaleBuyerYards4cfselect" access="remote" returntype="query" output="false">
<cfset var qGetSaleBuyerYards="">
<cfquery name="qGetSaleBuyerYards" datasource="#request.dsn#">
SELECT sale_buyer_yard_id, sale_buyer_yard
FROM sale_buyer_yard
WHERE sale_buyer_id = THE document.getElementById('sale_buyer_id').value FROM THE CALLING FORM
ORDER BY sale_buyer_yard
</cfquery>
<cfreturn qGetSaleBuyerYards />
</cffunction>
i also mean you js function the cfselect is bound to: bind="javascript:getSaleBu yerYards() ".
getSaleBuyerYards() javascript function - can you post its code, please?
i also assume you are using the function to open cfwindow Sid posted in your other question, right?
Azadi
getSaleBuyerYards() javascript function - can you post its code, please?
i also assume you are using the function to open cfwindow Sid posted in your other question, right?
Azadi
ASKER
Sorry... it actually should be bind="cfc:addWindow.getSal eBuyerYard s4cfselect ()".
To open the cfwindow I am calling the addSaleBuyerYard() function via <a href="javascript:addSaleBu yerYard(); ">[ add new ]</a>.
To open the cfwindow I am calling the addSaleBuyerYard() function via <a href="javascript:addSaleBu
<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 yard data
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});
};
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());
};
ASKER
So what I really need to do is pass the document.getElementById('s ale_buyer_ id').value into the getSaleBuyerYards4cfselect () cfc query.
ok.
can you also post the code of the page you display in your cfwindow, so i can make a complete code sample for you?
Azadi
can you also post the code of the page you display in your cfwindow, so i can make a complete code sample for you?
Azadi
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
actually, you can totally get rid of getSaleBuyerYards js function and just change your onHideAddSaleBuyerYard function to this:
var onHideAddSaleBuyerYard = function(name){ //refreshes the cfselect
var p = new salebuyeryardProxy();
var sbid = ColdFusion.getElementValue ('sale_buy er_id');
ColdFusion.Bind.assignValu e('sale_bu yer_yard_i d', 'value', p.getSaleBuyerYards4cfsele ct(sbid));
};
Azadi
var onHideAddSaleBuyerYard = function(name){ //refreshes the cfselect
var p = new salebuyeryardProxy();
var sbid = ColdFusion.getElementValue
ColdFusion.Bind.assignValu
};
Azadi
ASKER
It worked!!!! Perfect!
The only other thing I am missing now is when the page loads, all sale_buyer_yard_ids get listed since sbid has no value. Is there a way to pass the sbid argument to the getSaleBuyerYards4cfselect onload? So it selects the correct values for the initial record in sale_buyer_id?
I'm also getting a blank CFWINDOW page after I insert a new record... I think I have to clear the other one somehow? Not a big deal but if its easy, it would be nice to add.
The only other thing I am missing now is when the page loads, all sale_buyer_yard_ids get listed since sbid has no value. Is there a way to pass the sbid argument to the getSaleBuyerYards4cfselect
I'm also getting a blank CFWINDOW page after I insert a new record... I think I have to clear the other one somehow? Not a big deal but if its easy, it would be nice to add.
> So it selects the correct values for the initial record in sale_buyer_id?
what's the correct value and where is it stored (which cf or js variable)?
> I'm also getting a blank CFWINDOW page after I insert a new record
not quiet sure what you mean - is this after you click the 'submit' button in the page displayed in cfwindow, or is it when you try to add another sale_buyer_yard ?
Azadi
what's the correct value and where is it stored (which cf or js variable)?
> I'm also getting a blank CFWINDOW page after I insert a new record
not quiet sure what you mean - is this after you click the 'submit' button in the page displayed in cfwindow, or is it when you try to add another sale_buyer_yard ?
Azadi
ASKER
When the page loads, the sale_buyer_id select loads the full list of sale_buyers (getSaleBuyers4cfselect function).
Then the sale_buyer_yard_id select loads the getSaleBuyerYards4cfselect function but returns all records in the sale_buyer_yard table. I need it to load the records for the selected value in sale_buyer_id.
The query in the getSaleBuyerYards4cfselect function looks like this.. onload, it does not include the WHERE clause since we haven't passed any value for sbid. The sbid value should be the value of the initially loaded sale_buyer_id. That way it will select only it's records when the page loads.
<cfquery name="qGetSaleBuyerYards" datasource="#request.dsn#" >
SELECT sale_buyer_yard_id, sale_buyer_yard
FROM sale_buyer_yard
<cfif arguments.sbid gt 0>
WHERE sale_buyer_id = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.sbid#">
</cfif>
ORDER BY sale_buyer_yard
</cfquery>
When I add a new sale_buyer_yard_id using CFWINDOW, the first one works great. When I click to add another, the CFWINDOW pops up, but its blank.
Then the sale_buyer_yard_id select loads the getSaleBuyerYards4cfselect
The query in the getSaleBuyerYards4cfselect
<cfquery name="qGetSaleBuyerYards" datasource="#request.dsn#"
SELECT sale_buyer_yard_id, sale_buyer_yard
FROM sale_buyer_yard
<cfif arguments.sbid gt 0>
WHERE sale_buyer_id = <cfqueryparam cfsqltype="cf_sql_integer"
</cfif>
ORDER BY sale_buyer_yard
</cfquery>
When I add a new sale_buyer_yard_id using CFWINDOW, the first one works great. When I click to add another, the CFWINDOW pops up, but its blank.
" When I click to add another, the CFWINDOW pops up, but its blank."
probably a caching problem
you can try adding a unique id (wid) based on time to your window and also clearing the object cache after creating the window
var addSaleBuyerYard = function(){
var d = new Date()
var wid = d.getMinutes()+d.getSecond s()
var param = document.getElementById('s ale_buyer_ id').value ;
ColdFusion.Window.create(' sale_buyer _yard_id_w indow'+wid , 'Add Sub-Yard', 'add_SaleBuyerYard.cfm?sal e_buyer_id ' + param, {center:true,height:300,wi dth:380,cl osable:tru e,dragable :true,resi zable:true ,modal:tru e,initshow :true});
ColdFusion.objectCache["sa le_buyer_y ard_id_win dow"+wid = null;
};
probably a caching problem
you can try adding a unique id (wid) based on time to your window and also clearing the object cache after creating the window
var addSaleBuyerYard = function(){
var d = new Date()
var wid = d.getMinutes()+d.getSecond
var param = document.getElementById('s
ColdFusion.Window.create('
ColdFusion.objectCache["sa
};
> I need it to load the records for the selected value in sale_buyer_id.
which is the selected record in sale_buyer_id when the page loads? which variable is it stored in?
what you can try is change your sale_buyer_yard_id select to:
<cfselect name="sale_buyer_yard_id" id="sale_buyer_yard_id" bind="cfc:addWindow.getSal eBuyerYard s4cfselect ({sale_buy er_id})" bindonload="false" display="sale_buyer_yard" value="sale_buyer_yard_id" />
the above will load sale_buyer_yard_id with the values related to selected sale_buyer_id only (or related to the first sale_buyer_id if none was pre-selected on initial page load)
> When I click to add another, the CFWINDOW pops up, but its blank
you could use ColdFusion.navigate() fucntion instead of ColdFusion.Window.create() in your addSaleBuyerYard js function. you will need to already have a hidden empty cfwindow in your page for this to work:
a) add <cfwindow name="sale_buyer_yard_id_w indow" title="Add Sub-Yard" center="true" height="300" width="380" closable="true" dragable="true" resizable="true" modal="true" initshow="false"></cfwindo w>
to the bottom of your page, just before </body> tag
and change your addSaleBuyerYard js function to:
var addSaleBuyerYard = function(){
var param = document.getElementById('s ale_buyer_ id').value ;
ColdFusion.navigate( 'add_SaleBuyerYard.cfm?sal e_buyer_id =' + param, 'sale_buyer_yard_id_window ');
ColdFusion.Window.show('sa le_buyer_y ard_id_win dow');
};
Azadi
which is the selected record in sale_buyer_id when the page loads? which variable is it stored in?
what you can try is change your sale_buyer_yard_id select to:
<cfselect name="sale_buyer_yard_id" id="sale_buyer_yard_id" bind="cfc:addWindow.getSal
the above will load sale_buyer_yard_id with the values related to selected sale_buyer_id only (or related to the first sale_buyer_id if none was pre-selected on initial page load)
> When I click to add another, the CFWINDOW pops up, but its blank
you could use ColdFusion.navigate() fucntion instead of ColdFusion.Window.create()
a) add <cfwindow name="sale_buyer_yard_id_w
to the bottom of your page, just before </body> tag
and change your addSaleBuyerYard js function to:
var addSaleBuyerYard = function(){
var param = document.getElementById('s
ColdFusion.navigate( 'add_SaleBuyerYard.cfm?sal
ColdFusion.Window.show('sa
};
Azadi
ASKER
Perfect!! The only thing I have left is to fire the getSaleBuyerYards4cfselect function after I have entered a new sale_buyer_id which would requery to get the sale_buyer_yard_ids for that newly added sale_buyer_id. Otherwise, the values in sale_buyer_yard_id are incorrect.
I assume I could add something to the onHideAddSaleBuyer fucntion?
I assume I could add something to the onHideAddSaleBuyer fucntion?
was that ever part of your original question? this has been going on for so long i forget what was the original probelm... :)
i definitely do not see any code for onHideAddSaleBuyer function posted anywhere before... so why don;t you start a new question? :)
Azadi
i definitely do not see any code for onHideAddSaleBuyer function posted anywhere before... so why don;t you start a new question? :)
Azadi
ASKER
Thanks for the help Azadi!
I opened a new question about refiring the getSaleBuyerYards4cfselect function after a new sale_buyer_id is entered here...
https://www.experts-exchange.com/questions/24284602/Requery-chained-select-box-after-parent-insert.html
Please take a look.
Thanks again!
I opened a new question about refiring the getSaleBuyerYards4cfselect
https://www.experts-exchange.com/questions/24284602/Requery-chained-select-box-after-parent-insert.html
Please take a look.
Thanks again!
<select name="SelectBoxName">
<option value="Blah">Option 1</option>
<option value="Foo">Option 2</option>
</select>
Submit the form to a Coldfusion page. The value of the select box will be available as
Form.SelectBoxName