473,396 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Drop down menu option selected displays a textbox and a button

I have a form with a drop down box. If you select an option in the drop down box (depending which option is selected) one or two textbox(es) and a submit button display.
I would like to keep the textbox(es) and the submit button showing until another option is selected. Also the data that's submitted is showing on the form page.

Here's an example - I need the code below to do this:
1. I go to the page - I see a drop down box.
2. I select the first option - I see the drop down box, a textbox, and a submit button. I submit the info - the drop down box, the same textbox, and the submit button are still visible, with the data below the submit button.
3. I select the second option - I see the drop down box, two textboxes, and a submit button. I submit the info - the drop down box, the same two textboxes, and the submit button are still there with the data below the button, until I select the first option etc.

Here's what I have so far, it works but when I submit the textbox(es) don't show any longer but rather just the drop down box and the data submitted. Thanks for the help in advance.

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.  
  3. function toggle(show)
  4. {
  5.     if (this.currvisible) {
  6.         document.getElementById(currvisible).style.display = 'none';
  7.     }
  8.  
  9.     if (show) {
  10.         document.getElementById(show).style.display = '';
  11.         this.currvisible = show;
  12.     }
  13. }
  14.  
  15. </script>
  16.  
Expand|Select|Wrap|Line Numbers
  1. <form method="post" action="index.jsp">
  2.  
  3. <table cellpadding="0" cellspacing="0">
  4.     <tr>
  5.       <td>Make a Selection</td>
  6.    </tr>
  7.    <tr>
  8.       <td>
  9.         <select onchange="toggle(this.options[this.selectedIndex].value);">
  10.             <option value=''></option>
  11.             <option value="d1">d1</option>
  12.             <option value="d2">d2</option>
  13.        </select>
  14.       </td>
  15.       </tr>
  16. </table>
  17. <div id="d1" style="display: none;">
  18.    <table cellpadding="0" cellspacing="0">
  19.      <tr>
  20.          <td>Phone Number</td>
  21.       </tr>
  22.        <tr>
  23.            <td><input name="phoneNumber" /></td>
  24.        </tr>
  25.         <tr>
  26.            <td><input name="submit" type="submit" value="Submit" /></td>
  27.         </tr>
  28.    </table>
  29. </div>
  30.  
  31. <div id="d2" style="display: none;">
  32.        <table cellpadding="0" cellspacing="0">
  33.            <tr>
  34.     <td>Phone Number</td>
  35.            </tr>
  36.     <tr>
  37.         <td><input name="phoneNumber" /></td>
  38.     </tr>
  39.     <tr>
  40.         <td>Email Address</td>
  41.     </tr>
  42.     <tr>
  43.         <td><input name="emailAdress" /></td>
  44.     </tr>
  45.     <tr>
  46.         <td><input name="submit" type="submit" value="Submit" /></td>
  47.     </tr>
  48.   </table>
  49. </div>
  50.   <table>
  51.       <tr>
  52.           <td><c:out value="${param.results}"  /></td>
  53.       </tr>
  54.  </table>
  55. </form>
  56.  
Jun 16 '07 #1
1 5046
acoder
16,027 Expert Mod 8TB
Welcome to TSDN!

You could consider AJAX that would allow you to get the data from the server without unloading and reloading the page.
Jun 18 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: ehm | last post by:
I apologize in advance for the cross-post (from microsoft.public.inetexplorer.scripting), but that board seems dead. I have what I think is a fairly simple problem, but I cannot figure this out....
6
by: Greg Scharlemann | last post by:
I am attempting to populate a drop down menu based on the selection of a different drop down menu. However, it is not working correctly, I cannot figure out for the life of me what exactly happens...
1
by: Greg Scharlemann | last post by:
I would like to automatically populate a drop down menu when the page loads based on the selection of an item in a different drop down menu. I made a test page that when drop down #1 changes, drop...
3
by: JS | last post by:
I have two drop/down menus that are dependant on each other. When I have made a choice in both of these menus and press a button I get to a page depending on the choice made. On this page there is...
19
by: mart2006 | last post by:
I've created a dynamic drop down menu that populates itself with data from a MySQL table. What I would like to do is create a non dynamic drop down menu that alters what is shown in the dynamic menu....
11
by: vinceboy | last post by:
Hi..guys!I have a drop down menu with javascript null validation.However,instead of clicking submit button,it will immediately auto redirect after option was selected.Is it possible to prevent this...
2
by: giandeo | last post by:
Hello all, It's almost a couple of weeks since i am struggling to get this code work. Unfortunately, i am stuck. There seems to be no hope... Please Help....... I am working with an asp page...
10
by: mart2006 | last post by:
Hi, I'm fairly new to PHP and I've created a dynamic drop down menu that populates itself with data from a MySQL table. What I would like to do is create a non dynamic drop down menu that alters...
6
by: phpnewbie26 | last post by:
My current form has one multiple select drop down menu as well as few other drop down menus that are single select. Originally I had it so that the multiple select menu was first, but this created...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.