Solved

Javascript populate data in dropboxes

Posted on 2004-03-28
4
313 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

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…
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'…
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…

778 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