Solved

Get the current value of a select box.

Posted on 2009-03-30
22
1,307 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?

0
Comment
Question by:MFredin
  • 10
  • 8
  • 3
  • +1
22 Comments
 
LVL 16

Expert Comment

by:duncancumming
ID: 24023139
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


0
 

Author Comment

by:MFredin
ID: 24023364
0
 
LVL 36

Assisted Solution

by:SidFishes
SidFishes earned 150 total points
ID: 24023883
as per other q

remember that js values are client side only  To pass a js variable to a cfc you need use a form variable or use cfinvoke on your calling page.

ie if the url variable being passed in your cfwindow call was

add_SaleBuyerYard.cfm?sale_buyer_id=123

you'd

<cfinvoke ...>
         <cfinvokeargument name="sale_buyer_id" value="#ur;sale_buyer_id#">
</cfinvoke>

but since you are posting a form from the calling page, i think you'd probably just use the value from sale_buyer_id on your main form




0
 
LVL 36

Expert Comment

by:SidFishes
ID: 24023891
value="#ur;sale_buyer_id#

sb

value="#url.sale_buyer_id#
0
 

Author Comment

by:MFredin
ID: 24024008
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

0
 

Author Comment

by:MFredin
ID: 24024551
SidFishers,

Does that make sense?  I upped the points on this question... it's been stumping me for days!
0
 
LVL 27

Expert Comment

by:azadisaryev
ID: 24025070
what does your getSaleBuyerYards js function look like?
if it uses a cfc proxy, post the cfc function call as well.

Azadi
0
 

Author Comment

by:MFredin
ID: 24025118
Hi Azadi,

Do you mean my cfc?  

FYI: This question is somewhat of a continuation of this question... http://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

0
 
LVL 27

Expert Comment

by:azadisaryev
ID: 24025301
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
0
 

Author Comment

by:MFredin
ID: 24025377
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

0
 

Author Comment

by:MFredin
ID: 24025556
So what I really need to do is pass the document.getElementById('sale_buyer_id').value into the getSaleBuyerYards4cfselect() cfc query.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 27

Expert Comment

by:azadisaryev
ID: 24025843
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
0
 
LVL 27

Accepted Solution

by:
azadisaryev earned 350 total points
ID: 24025955
ok, it seemd to be simpler than i thought... maybe i just got a bit lost in what exactly your were trying to do...
hope i got it right...

all you need to do is:
- make your cfc function accept one optional argument - the value of selected sale_buyer_id
- pass the currently selected sale_buyer_id value to your cfc function when you refresh the yards list.

2 js functions and cfc function need slight changes. see edited functions attached.

hope this works... haven't really tested it, but it should...

Azadi
<!--- this is your new getSaleBuyerYards js function: --->
 

var getSaleBuyerYards = function(sbid){ //uses ajax proxy to populate cfselect

 if (!sbid) sbid=0;

 var p = new salebuyeryardProxy();

 var populate = p.getSaleBuyerYards4cfselect(sbid);

 return populate;

};
 
 

<!--- and this is your new onHideAddSaleBuyerYard js function: --->
 

var onHideAddSaleBuyerYard = function(name){ //refreshes the cfselect

 var sbid = document.getElementById('sale_buyer_id').value;

 ColdFusion.Bind.assignValue('sale_buyer_yard_id', 'value', getSaleBuyerYards(sbid));

};
 
 

<!--- and, finally, your new cfc function: --->
 

<cffunction name="getSaleBuyerYards4cfselect" access="remote" returntype="query" output="false">

<cfargument name="sbid" required="no" default="0">

<cfset var qGetSaleBuyerYards="">

<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>

<cfreturn qGetSaleBuyerYards />

</cffunction>

Open in new window

0
 
LVL 27

Expert Comment

by:azadisaryev
ID: 24026129
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
0
 

Author Comment

by:MFredin
ID: 24028528
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.  

0
 
LVL 27

Expert Comment

by:azadisaryev
ID: 24028612
> 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
0
 

Author Comment

by:MFredin
ID: 24028777
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.

0
 
LVL 36

Expert Comment

by:SidFishes
ID: 24028871
" 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;
};








0
 
LVL 27

Expert Comment

by:azadisaryev
ID: 24028949
> 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
0
 

Author Comment

by:MFredin
ID: 24029215
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?
0
 
LVL 27

Expert Comment

by:azadisaryev
ID: 24029349
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
0
 

Author Comment

by:MFredin
ID: 24038963
Thanks for the help Azadi!

I opened a new question about refiring the getSaleBuyerYards4cfselect function after a new sale_buyer_id is entered here...

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/Cold_Fusion_Markup_Language/Q_24284602.html

Please take a look.

Thanks again!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now