Solved

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

Posted on 2011-09-14
5
250 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
[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
  • 3
  • 2
5 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 500 total points
ID: 36542945
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
ID: 36542950
You likely want to run that onload too in case they reload the page
0
 

Author Comment

by:dmalovich
ID: 36543006
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
ID: 36543063
It seems to work in IE but not in firefox
0
 

Author Closing Comment

by:dmalovich
ID: 36543307
I got it to work.  I made a div tag for each field.  Thanks......
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

690 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