Solved

I want to move html form fields around after making a selection in a drop down box

Posted on 2011-09-14
5
246 Views
Last Modified: 2012-08-13
I've included the html form, css, and javascript.  When you select 'Alcohol Type', depending on your selection, the form changes.  For example, if you select 'Spirits', then it will also show 'Spirits Type' and 'Made Outside N.A., Mexico?'.   If you select 'Beer', 'Sprirt Cooelrs' or 'Wine Coolers'  then those 2 fields disappear.  If you select 'Wine', 'Cider', or 'Sparkling Wine' then another form field 'bottled in?' appears.  These are the 3 situations.  

Now what I'm trying to do is make this look cleaner when the selections are made.  What I mean is, for example, if you select 'Cider' I would like 'Bootled In?'  to align with 'Total Cost' field on the left and have it show 'Bottled In?' along the top of the form field.  I think this requires some JavaScript.  Also, if you select 'Spirits', I would like for 'Made Outside N.A., Mexico?' to align with 'Total Cost' on the left as well.
test.php
templatemo-style.css
config.js
0
Comment
Question by:dmalovich
  • 3
  • 2
5 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 500 total points
Comment Utility
Very simple

    if(chosen == 1) {
       document.getElementById("spiritType").style.display = "block";
        document.getElementsByName("outside_country")[0].style.display = "block";
    }
    else {
       document.getElementById("spiritType").style.display = "none";
        document.getElementsByName("outside_country")[0].style.display = "none";
    }


   <div id="spiritType">
            <label for="password1">Spirits Type</label>      
            <select style="width:150px;" name="spirits_type">
            <option value="">-- Select --</option>
            <option value="Whisky">Whisky</option>
            <option value="Rum">Rum</option>
            <option value="Vodka">Vodka</option>
            <option value="Tequila">Tequila</option>
            <option value="Gin">Gin</option>
            <option value="Liqueurs">Liqueurs</option>
            <option value="Brandy/Cognac">Brandy/Cognac</option>
            <option value="Other">Other</option>
        </select><br /><br /><br />
   </div>    
0
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
You likely want to run that onload too in case they reload the page
0
 

Author Comment

by:dmalovich
Comment Utility
I got it to hide thanks.  But, when I select 'Wine' for example, how can I move it up so it aligns evenly with
'Total Cost'.
0
 

Author Comment

by:dmalovich
Comment Utility
It seems to work in IE but not in firefox
0
 

Author Closing Comment

by:dmalovich
Comment Utility
I got it to work.  I made a div tag for each field.  Thanks......
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

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

728 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