Solved

how to add an extra (non-db) selection to a dynamically driven drop-down menu in CFML

Posted on 2012-12-22
1
255 Views
Last Modified: 2013-01-19
I have a search box/form that I am using to search through a query. I have a way of moving forward with the way that I want to do - but I feel like I may be stuck with a small problem.

The Page is going to submit to itself, and the search parameters are going to be stored as session variables. All the search criteria/selectors come from db fields themselves, so that they can be changed through the db/an administration interface.

After submitting the search criteria, the page will be populated with the appropriate results, and the search box (on the top of the page) will display the items and essential structure/form of the previous search. For instance, there is a drop down menu called 'titles' that is a part of the search box. If a title is selected as "pastor" then all pastors will be displayed in the search results, and the search box will be defaulted to the existing search variable which will be titles = 'pastors'. The menu will have all the other titles from the db, and it does have a section of id="0" which is for 'no title'.  But I need a selection to be in the search menu for titles, that is not just set to "0" but rather instead for just nothing, so that when the 'blank' selection is used, it just does not search only for users that have 'no title'  - but will be set to null so the the logic (that I will build) will not run the query for titles against the db for anything, either "0" ('No Title') or any other numbers ("2" = 'pastors,' for example).  Essentially I have 'name,' 'title,' and 'authority' search descriptors - and the title and authority are drop down menu, db-populated. I know that I could put a 'null' value in the db - but then I'd have to go back into all the other sections, and rewrite the queries so that they don't pull the 'null' value, because there is where I specifically set the users as having 'No Title".

does this make any sense?

it seems that it ought to be very very easy to add 'hardcoded' selections to a db-populated menu list.


thanks!
0
Comment
Question by:btintermedia
[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
1 Comment
 
LVL 36

Accepted Solution

by:
SidFishes earned 500 total points
ID: 38723833
It is pretty simple. Basically you just need to manually create an option before you loop through the returned data (or as in the case of the example below, a static array)

mySelect.options[0] = new Option ('Not Stated', '0');


<Script>  
 var vArr = new Array( 
['1','Tinker'],
['2','Tailor'],
['3','Soldier'],
['4','Spy'],
['5','Pastor'])


function init(){
var mySelect = document.getElementById('foo');

	 mySelect.options.length = 0;
	 mySelect.options[0] = new Option ('Not Stated', '0'); //create an option for array position [0]
     for (var c = 1; c < vArr.length; c++) { //loop over array starting at position [1] until done
          mySelect.options[c] = new Option(vArr[c][1],vArr[c][1]);
     }
}
	</script>		
	<body onLoad="init()">
			<select id="foo" name="foo">
			<option value="">--Please Select--</option>
			</select>
	</body>		

Open in new window

0

Featured Post

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Suggested Solutions

An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
This video teaches users how to migrate an existing Wordpress website to a new domain.
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…

737 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