SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    Level 8 Chinese guy Archbob's Avatar
    Join Date
    Sep 2001
    Location
    Somewhere in this vast universe
    Posts
    3,732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with dynamic forms

    Hey I have this javascript function
    Code:
    <script src="utility.txt"></script>
    <script type="text/javascript">
    <!--
    // function switchDiv()
    //  this function takes the id of a div
    //  and calls the other functions required
    //  to show that div
    //
    function switchDiv(div_id,div2,div3)
    {
      var style_sheet = getStyleObject(div_id);
      if (style_sheet)
      {
    	hideAll();
    	changeObjectVisibility(div_id,"visible");
    	if(div2!=0)
    	 {
    	   changeObjectVisibility(div2,"visible");
    	 }
       if(div3!=0)
    	{
    	  changeObjectVisibility(div3,"visible");
    	} 
      }
      else 
      {
    	alert("Please select an Option");
      }
    }
    // function hideAll()
    //  hides a bunch of divs
    //
    function hideAll()
    {
       changeObjectVisibility("Yes","hidden");
       changeObjectVisibility("No","hidden");
       changeObjectVisibility("Yes1","hidden");
       changeObjectVisibility("No1","hidden");
    }
    // function getStyleObject(string) -> returns style object
    //  given a string containing the id of an object
    //  the function returns the stylesheet of that object
    //  or false if it can't find a stylesheet.  Handles
    //  cross-browser compatibility issues.
    //
    function getStyleObject(objectId) {
      // checkW3C DOM, then MSIE 4, then NN 4.
      //
      if(document.getElementById && document.getElementById(objectId)) {
     return document.getElementById(objectId).style;
       }
       else if (document.all && document.all(objectId)) {  
     return document.all(objectId).style;
       } 
       else if (document.layers && document.layers[objectId]) { 
     return document.layers[objectId];
       } else {
     return false;
       }
    }
    function changeObjectVisibility(objectId, newVisibility) {
    	// first get a reference to the cross-browser style object 
    	// and make sure the object exists
    	var styleObject = getStyleObject(objectId);
    	if(styleObject) {
     styleObject.visibility = newVisibility;
     return true;
    	} else {
     // we couldn't find the object, so we can't change its visibility
     return false;
    	}
    }
    // -->
    </script>

    Now I have the following chunk:
    Code:
    print "<td><input type='radio' name='cnenable' value='Yes' onclick=\"switchDiv(document.theform.privacyfilter.value,'Yes','0')\";>&nbsp;Enable</td>";
    print "<td><input type='radio' name='cnenable' value='No'  onclick=\"switchDiv(document.theform.privacyfilter.value,'No','0')\";>&nbsp;Disable</td></tr>";
    print "<tr><td>Privacy Filter</td>";
    print "<td><input type='radio' name='privacyfilter' value='Yes1' onclick=\"switchDiv(document.theform.cnenable.value,'Yes1','0')\">&nbsp;Enable</td>";
    print "<td><input type='radio' name='privacyfilter' value='No1'  onclick=\"switchDiv(document.theform.cnenable.value,'No1','0')\">&nbsp;Disable</td></tr></table>";
    The problem is the javascript function is not reading the first parameter. I named the div according the the values of the radio buttons. I want the form to display 2 divs when both privacy and cnenable are checked but its only showing one. Help.

  2. #2
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Answered in www.htmlforums.com

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •