Solved

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

Posted on 2011-09-14
5
247 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how can i make a sum of digits work when the first number is negative? 5 44
Javasctipt 2 25
jquery datepciker end date add 6 days 6 35
How to show span when clicked on? 10 20
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

776 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