Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2011-09-14
5
Medium Priority
?
253 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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
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…

618 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