Solved

disable a <div functions by radio button

Posted on 2007-03-23
6
1,824 Views
Last Modified: 2012-05-05
I have two radio buttons and two section declared by <div> tab. Now I want to

1. by default, <div> 1 is open and <div> 2 is disable, not hidden
2. By clicking  radio button 2, <div> 2 open and <div> 1 become disabled
3. By clicking radio button 1, <div> 1 open and <div> 2 become disabled

How can I do that? It is possible not to use JS but HTML? JS is fine to me too if i have to.

Here is my code

<div>
    <form name="IP_to_MAC" action="<portlet:actionURL/>" method="post" onSubmit="return ValidateForm()" >
       
            <div style="padding-top:5px;padding-bottom:5px;" id="ICC">
              <fieldset class="portlet-font">
                <legend >Type</legend>
                <input name="VolContID" type="hidden" value="999" >
               
         
                <input name="Sch_IP_Addr" type="radio" value="Sch_IP_Addr" >Search for IP Address                              
                <input name="Sch_MAC_Addr" type="radio" value="Sch_MAC_Addr"  checked  >Search for MAC Address
                <br>
                </fieldset>
<br>
                   <div >
                        <label>Search for MAC Address: <input type="text" name="MACAddress" size="20" maxlength="25" > </label>


                       <label>on the:
                           <select  id="netname" name="netname" type="text" >

                                 <option selected  >uiuc-citesstaff-net</option>
                                   <option >uiuc-bioeng-net</option>
                                     <option >uiuc-teste-net</option>


                           </select>
                      </label>
 <br>
                   </div>
       
                    <div class="disabled" style="padding-top:5px;padding-bottom:5px; visibility;" id="IPC" >

                        <label>Search for IP Address: <input type="text" name="IPAddress" size="20" maxlength="25" > </label>


                        <label>on the MAC Address:
                            <select id="MACname" name="MACname" type="text" >

                                  <option selected  >00:0A:95:77:C3:CE</option>
                                    <option>00:06:5B:62:D5:EB</option>
                                      <option  >00:06:5B:A6:AD:EC</option>

                            </select>
                        </label>

                    </div>
       
 
0
Comment
Question by:wasabi3689
  • 2
6 Comments
 
LVL 35

Expert Comment

by:mrichmon
ID: 18783890
>>It is possible not to use JS but HTML
No.

You must use javascript if you want it to change based on user interaction (such as clicking a radion button)

>>1. by default, <div> 1 is open and <div> 2 is disable, not hidden
You can't disable a div, but you could disable each input inside, then use javascript to toggle the inputs/selects/etc within the two divs between disabled and enabled.

You would use

to disable:
document.getElementById("IdNameHere").style.disabled = true;

to enable:
document.getElementById("IdNameHere").style.disabled = false;

Repeat for each input/select/etc

To trigger use the onclick of the radio button to detect which one is selected and set the statuses accordingly.
0
 

Author Comment

by:wasabi3689
ID: 18784257
Here is what I code, but it doesn't work. Can you figure out the problem?

<script language="JavaScript">
               
                    function toggleVisibility(me){
                    if (document.getElementById("MAC").style.disabled = true){
                      document.getElementById("IP").style.disabled = false;
                            }
                        else {
                        document.getElementById("IP").style.disabled = true;
                    }
                }
                </script>
               
         
                <input name="Sch_IP_Addr" type="radio" value="Sch_IP_Addr" onclick="toggleVisibility(me)" >Search for IP Address                              
                <input name="Sch_MAC_Addr" type="radio" value="Sch_MAC_Addr"  checked onclick="toggleVisibility(me)"  >Search for MAC Address
                <br>
                </fieldset>
<br>
                   <div id="MAC" style="disabled" >
                        <label>Search for MAC Address: <input type="text" name="MACAddress" size="20" maxlength="25" > </label>


                       <label>on the:
                           <select  id="netname" name="netname" type="text" >

                                 <option selected  >uiuc-citesstaff-net</option>
                                   <option >uiuc-bioeng-net</option>
                                     <option >uiuc-teste-net</option>


                           </select>
                      </label>
 
                   </div>
   <br>    
                    <div id="IP" style="padding-top:5px;padding-bottom:5px; visibility;" id="IPC" >

                        <label>Search for IP Address: <input type="text" name="IPAddress" size="20" maxlength="25" > </label>


                        <label>on the MAC Address:
                            <select id="MACname" name="MACname" type="text" >

                                  <option selected  >00:0A:95:77:C3:CE</option>
                                    <option>00:06:5B:62:D5:EB</option>
                                      <option  >00:06:5B:A6:AD:EC</option>

                            </select>
                        </label>

                    </div>
       
         
          </div>
0
 

Author Comment

by:wasabi3689
ID: 18784391
Why it doesn't work

I modify the code as bellow

     <script language="JavaScript">
               
                    function toggleVisibility(me){
                   {
                     
                     
                     if (document.IP_to_MAC.MACname.disabled = true) {
                       
       
                        document.IP_to_MAC.MACAddress.disabled = false;
                        document.IP_to_MAC.netname.disabled = false;
                      }
                           
                        }
                       
                        function toggleVisibility2(me){
                       {
                     
                             document.IP_to_MAC.MACname.disabled = false;
                             document.IP_to_MAC.IPAddress.disabled = false;
                     
                              document.IP_to_MAC.MACAddress.disabled = true;
                              document.IP_to_MAC.netname.disabled = true;
                     
                       
                        }
                       
               
                </script>
               
         
                <input name="Sch_IP_Addr" type="radio" value="Sch_IP_Addr" onclick="toggleVisibility(me)" >Search for IP Address                              
                <input name="Sch_MAC_Addr" type="radio" value="Sch_MAC_Addr"  checked onclick="toggleVisibility2(me)"  >Search for MAC Address
                <br>
                </fieldset>
<br>
                   <div id="MAC" >
                        <label>Search for MAC Address: <input type="text" name="MACAddress" size="20" maxlength="25" > </label>


                       <label>on the
                           <select  id="netname" name="netname" type="text" >

                                 <option selected  >uiuc-citesstaff-net</option>
                                   <option >uiuc-bioeng-net</option>
                                     <option >uiuc-teste-net</option>


                           </select>
                      </label>
 
                   </div>
   
                    <div id="IPC"  style="padding-top:5px;padding-bottom:5px; visibility:disabled;" >

                        <label>Search for IP Address: <input type="text" name="IPAddress" size="20" maxlength="25" disabled  > </label>

                        <label>on the MAC Address:
                            <select id="MACname" name="MACname" type="text" disabled >

                                  <option selected >00:0A:95:77:C3:CE</option>
                                    <option>00:06:5B:62:D5:EB</option>
                                      <option  >00:06:5B:A6:AD:EC</option>

                            </select>
                        </label>

                    </div>
       
         
          </div>
         

I have two onclick for two radio buttons.
When I click radio button "Search for IP Address",  the input fields "Search For MAC Address" is not auto disbled? Why ?
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 50 total points
ID: 19348503
Too many syntax errors.

Here is a version I think works how you want it.
Change the IP and !IP around if I was wrong

<html>
<head>

<script language="JavaScript">
function toggleVisibility(theRad) {
  var IP = (theRad.value=='Sch_IP_Addr')?true:false;
  theRad.form.IPAddress.disabled = !IP;
  theRad.form.MACname.disabled = !IP;
  theRad.form.MACAddress.disabled = IP;
  theRad.form.netname.disabled = IP;
}
</script>
</head>
<body onLoad="if(document.forms[0].Sch_Addr[0].checked) toggleVisibility(document.forms[0].Sch_Addr[0]); else toggleVisibility(document.forms[0].Sch_Addr[1])">
<form>
<input name="Sch_Addr" type="radio" value="Sch_IP_Addr" onclick="toggleVisibility(this)" >Search for IP Address
<input name="Sch_Addr" type="radio" value="Sch_MAC_Addr" checked onclick="toggleVisibility(this)" >Search for MAC Address
<br>
</fieldset>
<br>
<div id="MAC" >
<label>Search for MAC Address: <input type="text" name="MACAddress" size="20" maxlength="25" > </label>


<label>on the
<select id="netname" name="netname" type="text" >

<option selected >uiuc-citesstaff-net</option>
<option >uiuc-bioeng-net</option>
<option >uiuc-teste-net</option>


</select>
</label>

</div>

<div id="IPC" style="padding-top:5px;padding-bottom:5px; visibility:disabled;" >

<label>Search for IP Address: <input type="text" name="IPAddress" size="20" maxlength="25"> </label>

<label>on the MAC Address:
<select id="MACname" name="MACname" type="text">

<option selected >00:0A:95:77:C3:CE</option>
<option>00:06:5B:62:D5:EB</option>
<option >00:06:5B:A6:AD:EC</option>

</select>
</label>

</div>


</div>
</form>
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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

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

11 Experts available now in Live!

Get 1:1 Help Now