Solved

Javascript populate data in dropboxes

Posted on 2004-03-28
4
312 Views
Last Modified: 2008-03-17
I have two dropboxes, Select1, Select2 in Form2. Select1 has 5 options. Select2 is disabled. Only if i select "money order or check" options, in first dropbox, second dropbox should be active and give its two options and i cannot skip without selecting anything from the second dropdown.

Code is as follows.

<html>
      <head>
            
      </head>
      <body>
            <TABLE border="0">
                  <TR>
                        <form id="Form2" name="Form2" action="" method="post">
                              <TD width="127">Payment Method:</TD>
                              <TD><SELECT id="Select1" name="Select1">
                                          <OPTION value="0" selected></OPTION>
                                          <OPTION value="1">Computer</OPTION>
                                          <OPTION value="2">Pay by Phone</OPTION>
                                          <OPTION value="3">Wire Transfer</OPTION>
                                          <OPTION value="4">Money Order</OPTION>
                                          <OPTION value="5">Check</OPTION>
                                    </SELECT></TD>                        
                  </TR>
                  <TR>                        
                              <TD width="127">Mailing Method:</TD>
                              <TD><SELECT id="Select2" name="Select2">
                                          <OPTION value="7" selected></OPTION>
                                          <OPTION value="8">Overnight</OPTION>
                                          <OPTION value="9">Regular</OPTION>
                                    </SELECT></TD>
                  </TR>
                  </form>
            </TABLE>
      </body>
</html>

Thanks in advance for ur help.

Ragz.
0
Comment
Question by:babasri101
  • 3
4 Comments
 
LVL 30

Expert Comment

by:third
ID: 10700793
<html>
     <head>
         
     </head>
     <body>
          <TABLE border="0">
               <TR>
                    <form id="Form2" name="Form2" action="" method="post">
                         <TD width="127">Payment Method:</TD>
                         <TD><SELECT id="Select1" name="Select1" onchange="this.form.Select2.disabled = this.selectedIndex <= 3;">
                                   <OPTION value="0" selected></OPTION>
                                   <OPTION value="1">Computer</OPTION>
                                   <OPTION value="2">Pay by Phone</OPTION>
                                   <OPTION value="3">Wire Transfer</OPTION>
                                   <OPTION value="4">Money Order</OPTION>
                                   <OPTION value="5">Check</OPTION>
                              </SELECT></TD>                    
               </TR>
               <TR>                    
                         <TD width="127">Mailing Method:</TD>
                         <TD><SELECT id="Select2" name="Select2" disabled>
                                   <OPTION value="7" selected></OPTION>
                                   <OPTION value="8">Overnight</OPTION>
                                   <OPTION value="9">Regular</OPTION>
                              </SELECT></TD>
               </TR>
               </form>
          </TABLE>
     </body>
</html>
0
 
LVL 30

Accepted Solution

by:
third earned 300 total points
ID: 10700809
modified a bit,

<html>
     <head>
          <script>
                 function flag(obj){
                     obj.form.Select2.selectedIndex = 0;
               obj.form.Select2.disabled = obj.selectedIndex <= 3;
                   }
              </script>
     </head>
     <body>
          <TABLE border="0">
               <TR>
                    <form id="Form2" name="Form2" action="" method="post">
                         <TD width="127">Payment Method:</TD>
                         <TD><SELECT id="Select1" name="Select1" onchange="flag(this)">
                                   <OPTION value="0" selected></OPTION>
                                   <OPTION value="1">Computer</OPTION>
                                   <OPTION value="2">Pay by Phone</OPTION>
                                   <OPTION value="3">Wire Transfer</OPTION>
                                   <OPTION value="4">Money Order</OPTION>
                                   <OPTION value="5">Check</OPTION>
                              </SELECT></TD>                    
               </TR>
               <TR>                    
                         <TD width="127">Mailing Method:</TD>
                         <TD><SELECT id="Select2" name="Select2" disabled>
                                   <OPTION value="7" selected></OPTION>
                                   <OPTION value="8">Overnight</OPTION>
                                   <OPTION value="9">Regular</OPTION>
                              </SELECT></TD>
               </TR>
               </form>
          </TABLE>
     </body>
</html>
0
 
LVL 12

Assisted Solution

by:lil_puffball
lil_puffball earned 200 total points
ID: 10700852
To make sure the user selects something put this in your form tag:

<form id="Form2" name="Form2" action="" method="post" onsubmit="if(this.form.select2.disabled=false&&this.form.select2.selectedIndex==0){alert('Please choose something from select 2.');return false;}">
0
 
LVL 30

Expert Comment

by:third
ID: 10700905
babasri101,

thanks!



lil_puff,

or just

if(this.form.select2.selectedIndex==0){alert('Please choose something from select 2.');return false;}

if babasri101 used my second post.

;-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Form with Modals 16 44
Enter key on html form page 11 48
How to change pointer icon to hand icon on mouseover 2 19
Materializecss - Different Behaviors in Browser's 1 20
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'…
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…

895 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now