Solved

disable a <div functions by radio button

Posted on 2007-03-23
6
1,829 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
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 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)

622 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