I am trying to do a dropdown of the suburbs and the selected value would show the corresponding details. I have managed to workout a code but its not working properly....
I mean its not working at all!!!
Even the basic html wont show!!
Please help me with this. I have the code written but I am in a mess here.
Check the browser error console and look for whatever is breaking your JS.
__________________ ^_^
If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
* The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".
That is ghastly code. Simply set all the suburb names paras to "hide", and then set the one that is required to "show".
Why are you using jQuery for such a simple task?
The closing CODE tag is /CODE.
Do please read the posting guidelines regarding silly thread titles. The thread title is supposed to help people who have a similar problem in future. Yours is useless for this purpose. You can (and should) edit it to make it more meaningful.
All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
__________________
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
then onto the javascript. You can use your onchange function to hide everything in that class (most of it will already be hidden, but hiding it twice makes no difference), then show the one you are interested in:
Code:
$("#event_type_id").change(function () {
$(".suburb").hide();
var val = $(this).val();
switch(parseInt(val)){
case 1:
$("#Alexandra Headlands").show();
//etc
or, refactoring a little more, you can save your self may more code, by storing the id of the div in the value of the select and using that to tell the code what to show. With your html like this:
Code:
<div class="suburb" id="Alexandra_Headlands">Events</div>
<div class=suburb" id="Battery_Hill" >Announcements</div>
<select id="event_type_id" name="event_type_id">
<option>Please select the suburb you want to know about</option>
<option value="Alexandra_Headlands" rel="Alexandra Headlands">Alexandra Headlands</option>
<option value="Battery_Hill" rel="Battery Hill">Battery Hill</option>
</select>
your entire function could look like this:
Code:
$("#event_type_id").change(function () {
$(".suburb").hide();
var theburb = $(this).val();
$("#"+theburb).show();
});