vijay Posted June 20, 2007 Share Posted June 20, 2007 Hi....The Following code is working in IE but not in Firefox....-----------------------------------------------------------------------------------------------------------------------<script language="javascript" type="text/javascript"> function enableDiv(divId) { document.getElementById(divId).enabled =true; }</script>and <div id="divId" disabled> <!-- form elements --></div>-----------------------------------------------------------------------------------------------------------------------Thanks in Advance...Best Regards,Vijay Link to comment Share on other sites More sharing options...
Lulzim Posted June 20, 2007 Share Posted June 20, 2007 I'm not sure if you can disable the form elements by 'disabling' the div which contains the form controls.Disabled is a property of form controls, not for div.The only way I know is to disable form elements one by one, or just disable the submit button. The Following code is working in IE but not in Firefox....if it works in IE doesn't mean that that's the right way to do it. Link to comment Share on other sites More sharing options...
vijay Posted June 20, 2007 Author Share Posted June 20, 2007 Hi.... yes, we can disable it via java script but we cannot enable it. that I have checked by small example its in the following code.. and @ last what ever you told thats solution there...Regards,Vijay-------------------------------------------------------------------------------------------------------------------------<?phprequire_once "../functions.php";?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title></title><style type="text/css"> body { font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;}</style><script language="javascript" type="text/javascript">function disablediv(divId){ alert(document.getElementById('tbl'+divId)); document.getElementById('tbl'+divId).disabled=true;}function enableDiv(divId){ alert(document.getElementById('tbl'+divId)); document.getElementById('tbl'+divId).disabled=false;}</script></head><body onload="disableAll()"><?php _pr($_REQUEST);?><h2 align="center">Example for disabled div in IE as well as FF</h2><div id="mainDiv"> <table width="780" border="0" align="center" cellpadding="0" cellspacing="0" class="border"> <tr> <td style="padding-top:10px;"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td valign="top" class="text-padding"><br /> <form id="form1" name="form1" method="post" onsubmit=""> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="dotedline"> </td> </tr> <tr> <td class="dotedline"><input name="Submit1" type="submit" id="Submit1" onClick='' value="Submit" /></td> </tr> <tr> <td height="25" valign="top"><table width="100%" border="0" cellpadding="2" cellspacing="0"> <tr> <td ><input type="hidden" name="tblid" value="" /> <input type="radio" name="regRadio" id="regRadio" onclick="disablediv(this.value)" class="radio-border" value="120" /> <strong>Portland & vicinity</strong> </td> </tr> <tr> <td><div id="tbl120"> <table id="tbl120_1" cellpadding="0" cellspacing="0" width="100%" style="display:" onclick=""> <tr> <td scope="col"><input type="checkbox" name="townid[]" value="698" id="townid" > town1</td> <td scope="col"><input type="checkbox" name="townid[]" value="697" id="townid" > town6</td> </tr> <tr> <td scope="col"><input type="checkbox" name="townid[]" value="701" id="townid" > town2</td> <td scope="col"><input type="checkbox" name="townid[]" value="694" id="townid" > town7</td> </tr> <tr> <td scope="col"><input type="checkbox" name="townid[]" value="695" id="townid" > town3</td> <td scope="col"><input type="checkbox" name="townid[]" value="700" id="townid" > town8</td> </tr> <tr> <td scope="col"><input type="checkbox" name="townid[]" value="896" id="townid" > town4</td> <td scope="col"> </td> </tr> <tr> <td scope="col"><input type="checkbox" name="townid[]" value="898" id="townid" > town5 </td> </table> <!----></div> </td> </tr> <tr> <td> </td> </tr> <tr> <td> <input name="Submit" type="submit" id="Submit" onClick='' value="Submit" /></td> </tr> </table></td> </tr> </table> </form></td> </tr> </table></td> </tr> <tr> <td><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td><img src="Resources/images/right-box-top.gif" width="100%" height="1" /></td> </tr> </table></td> </tr> </table></div></body></html>------------------------------------------------------------------------------------------------------------------------- Link to comment Share on other sites More sharing options...
jesh Posted June 20, 2007 Share Posted June 20, 2007 Like Lulzim said, I don't believe it makes any sense to disable a div element and doing so isn't going to propagate that status to all the form elements inside the div. You have to do that one element at a time - as Lulzim also said.An example of how that is possible is something like this: function toggleFormElements(divID, disabled){ var div = document.getElementById(divID); if(div) { var inputs = div.getElementsByTagName("input"); var selects = div.getElementsByTagName("select"); var textareas = div.getElementsByTagName("textarea"); for(var i = 0; i < inputs.length; i++) { inputs[i].disabled = disabled; } for(var i = 0; i < selects.length; i++) { selects[i].disabled = disabled; } for(var i = 0; i < textareas.length; i++) { textareas[i].disabled = disabled; } }} Which you could call like this: // disable the elementstoggleFormElements("MainDiv", true);// enable the elementstoggleFormElements("MainDiv", false); Link to comment Share on other sites More sharing options...
vijay Posted June 21, 2007 Author Share Posted June 21, 2007 Hi.. Thanks for ur help.. have done it same way as you suggested..Regards,Vijay Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.