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
Solved

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

Posted on 2011-09-14
5
248 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
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

808 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