Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Javascript dropdown needs variable name, multiple dropdowns

Posted on 2010-01-07
Medium Priority
Last Modified: 2012-06-27
Hi Experts,

I have copied 2 snippets of code in separated by a big line.

Basically we have a javascript drop down box ($("#genre")) and where it says genre here, that has to match the id of the html of the drop down box, otherwise it doesnt work.

We have a foreach rooms as room, i.e. with have x rooms, x drop down boxes.
How can I make this code match the javascript to work x times.

Can I use a variable, perhaps the name of the room instead of genre?

If you need to see more code, please ask

make sense?  



<script type="text/javascript">
        $(document).ready(function() {
	    $("#genre").dropdownchecklist({ maxDropHeight: 120 });


<tr align="right">
                        <td colspan="2" align="left" valign="top"><table width="528" border="0" cellpadding="3" cellspacing="0">
                            <tr><th width="14%" class="tx_esq_11_gray"><strong>Artist</strong></th><th width="14%" class="tx_esq_11_gray"><strong>Time</strong></th></tr>
                            <?php foreach ($rooms as $room): ?>
			    <tr valign="top">
				<td width="100"><span class="tx_esq_14_red_c"><?php htmlout($room['roomname']); ?><br /></span> </td>
                            <td width="300" valign="middle">      
			    <select name="genres[]" multiple="multiple" id="genre">
			    <?php foreach ($genres as $genre): ?>
					<option value= "<?php htmlout($genre['id']); ?>"<?php
							if ($genre['selected'])
								echo ' selected="selected"';
							?>><?php htmlout($genre['genrename']); ?></option>
                            <?php endforeach; ?>
		  <?php endforeach; ?>

Open in new window

Question by:MWatkins84
LVL 22

Accepted Solution

kadaba earned 2000 total points
ID: 26206738
<select name="genres[]" multiple="multiple" id="genre">
instead of id make it
<select name="genres[]" multiple="multiple" class="genre">

and then the script will be
$(".genre").dropdownchecklist({ maxDropHeight: 120 });


Author Closing Comment

ID: 31674383


Featured Post

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.

Question has a verified solution.

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

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Suggested Courses

571 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