Solved

CFSELECT and Show/Hide DIV

Posted on 2012-04-03
8
756 Views
Last Modified: 2012-04-03
If I choose option value 1, from the "First select"
results from both div id="d0" and div id="d1" are sent via a form.

First select:
<SELECT id="ptype" NAME="business_category_main" onchange="toggleSubmit(this)">
<option value="1">Culture, Entertainment & Recreation</option>
<option value="2">Drinking & Dining</option>
</select>


Second select:
<div id="d0" style="display:block">
<select  class="wpcf7-text textbox" name="business_subcategory">
<option VALUE="1">Art Studios, Galleries & Artists</option>
<option VALUE="2">Movie Theaters</option>
<option VALUE="3">Fitness, Sports & Recreation</option>
<option VALUE="4">Performance Venues</option>
<option VALUE="5">Travel & Lodging</option>
</select></div>
<div id="d1" style="display:none">
<select  class="wpcf7-text textbox" name="business_subcategory">
<option VALUE="6">Cafes & Bakeries</option>
<option VALUE="7">Catering</option>
<option VALUE="8">Delis & Grocers</option>
<option VALUE="9">Restaurants & Eateries</option>
<option VALUE="10">Bars, Taverns & Lounges</option>
<option VALUE="11">Wine, Liquor & Spirits</option>
</select></div>
0
Comment
Question by:swaggrK
  • 3
  • 3
  • 2
8 Comments
 
LVL 52

Expert Comment

by:_agx_
Comment Utility
What is your question?
0
 
LVL 20

Expert Comment

by:Proculopsis
Comment Utility
Check out this jsfiddle:

The code is:

function toggleSubmit(caller) {

    $("#d0").toggle();
    $("#d1").toggle();

}

Open in new window

0
 
LVL 20

Expert Comment

by:Proculopsis
Comment Utility
...or jsfiddle if you want the select removed:

The code is:

function toggleSubmit(caller) {

    $("#d0").toggle();
    $("#d1").toggle();

}

function onSubmit() {

    $("#d0").not(":visible").remove();
    $("#d1").not(":visible").remove();

}

Open in new window

0
 

Author Comment

by:swaggrK
Comment Utility
hmm... testing what u sent. I forgot to include the following in my initial post...
Basically, it is not submitting just ONE result but a result from "d0" and "d1"

<script type='text/javascript'>

function toggleSubmit(obj){

count=0
while(document.getElementById("d"+count)){
document.getElementById("d"+count).style.display="none"
count++
}
document.getElementById("d"+obj.selectedIndex).style.display="block"

}
</script>
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 52

Expert Comment

by:_agx_
Comment Utility
Edit: Doh, just realized you're hiding the DIV not the select lists. Try the previous suggestion.
0
 
LVL 20

Accepted Solution

by:
Proculopsis earned 150 total points
Comment Utility
The newer version removes the unused select from the form.
0
 

Author Comment

by:swaggrK
Comment Utility
AGX, that may work, but the results are submitted as followed...

1,6

With 1,6 being
<option VALUE="1">Art Studios, Galleries & Artists</option>
and
<option VALUE="6">Cafes & Bakeries</option>

Not sure how I would write a cfif that would take the 1 or the 6


<div id="d0" style="display:block">
<select  class="wpcf7-text textbox" name="business_subcategory">
<option VALUE="1">Art Studios, Galleries & Artists</option>
<option VALUE="2">Movie Theaters</option>
<option VALUE="3">Fitness, Sports & Recreation</option>
<option VALUE="4">Performance Venues</option>
<option VALUE="5">Travel & Lodging</option>
</select></div>
<div id="d1" style="display:none">
<select  class="wpcf7-text textbox" name="business_subcategory">
<option VALUE="6">Cafes & Bakeries</option>
<option VALUE="7">Catering</option>
<option VALUE="8">Delis & Grocers</option>
<option VALUE="9">Restaurants & Eateries</option>
<option VALUE="10">Bars, Taverns & Lounges</option>
<option VALUE="11">Wine, Liquor & Spirits</option>
</select></div>
0
 
LVL 52

Expert Comment

by:_agx_
Comment Utility
Actually I missed the earlier part about hiding the div, not the lists. Try hiding the select lists instead. I believe they won't show up on the action page if they're not visible.
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

As a result of several questions about how to use Bootstrap I thought it would be a good idea to write down the development aspect of creating a Bootstrapped website in as little time as possible. Part 1 of this article will only concentrate on g…
So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
In this tutorial viewers will learn how to customize the background color and font color of highlighted text using the ::selection element in CSS Begin by defining the selected text as an element in CSS by typing "::selection": Style the ::selection…
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…

744 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

13 Experts available now in Live!

Get 1:1 Help Now