We help IT Professionals succeed at work.

Get the current value of a select box.

MFredin
MFredin asked
on
1,580 Views
Last Modified: 2012-05-06
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?

Comment
Watch Question

Form field looks like
<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


CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT

Commented:
value="#ur;sale_buyer_id#

sb

value="#url.sale_buyer_id#

Author

Commented:
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:getSaleBuyerYards 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('sale_buyer_id').value.  Just not sure how to do that.   So I guess I need to figure out how to pass document.getElementById('sale_buyer_id').value to the cfc and use it in the WHERE clause.
<!--- 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" />

Open in new window

Author

Commented:
SidFishers,

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

Author

Commented:
Hi Azadi,

Do you mean my cfc?  

FYI: This question is somewhat of a continuation of this question... https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/Cold_Fusion_Markup_Language/Q_24278303.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>

Open in new window

i also mean you js function the cfselect is bound to: bind="javascript:getSaleBuyerYards()".
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

Author

Commented:
Sorry... it actually should be bind="cfc:addWindow.getSaleBuyerYards4cfselect()".

To open the cfwindow I am calling the addSaleBuyerYard() function via <a href="javascript:addSaleBuyerYard();">[ add new ]</a>.






<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());
};

Open in new window

Author

Commented:
So what I really need to do is pass the document.getElementById('sale_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
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
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_buyer_id');
 ColdFusion.Bind.assignValue('sale_buyer_yard_id', 'value', p.getSaleBuyerYards4cfselect(sbid));
};

Azadi

Author

Commented:
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.  

> 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

Author

Commented:
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.

CERTIFIED EXPERT

Commented:
" 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.getSeconds()
var param = document.getElementById('sale_buyer_id').value;
 ColdFusion.Window.create('sale_buyer_yard_id_window'+wid, '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});

ColdFusion.objectCache["sale_buyer_yard_id_window"+wid = null;
};








> 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.getSaleBuyerYards4cfselect({sale_buyer_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_window" title="Add Sub-Yard" center="true" height="300" width="380" closable="true" dragable="true" resizable="true" modal="true" initshow="false"></cfwindow>
to the bottom of your page, just before </body> tag

and change your addSaleBuyerYard js function to:

var addSaleBuyerYard = function(){
var param = document.getElementById('sale_buyer_id').value;
ColdFusion.navigate( 'add_SaleBuyerYard.cfm?sale_buyer_id=' + param, 'sale_buyer_yard_id_window');
ColdFusion.Window.show('sale_buyer_yard_id_window');
};

Azadi

Author

Commented:
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?
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

Author

Commented:
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/Web_Development/Web_Languages-Standards/Cold_Fusion_Markup_Language/Q_24284602.html

Please take a look.

Thanks again!

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.